Browse Source

git gud

pull/6/head
DanielFGray 3 years ago
parent
commit
7dd8b1f9dc
5 changed files with 30 additions and 23 deletions
  1. 12
    13
      fzgit
  2. 1
    1
      fzmp
  3. 7
    3
      fzmv
  4. 3
    0
      ix
  5. 7
    6
      pkgsearch

+ 12
- 13
fzgit View File

@@ -185,27 +185,25 @@ declare -A implemented_git_cmds=(
['stash']='git_stash'
['add']='git_add'
['checkout']='git_checkout'
['commit']='git commit -e'
['commit']='git commit -v'
['push']='git push'
['log']='git_log'
)

git_log() { # {{{
local out commit
while out=$(git log --graph --color=always \
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf -e --prompt='log' --no-sort --tiebreak=index --toggle-sort=\`)
do
commit=$(grep -m1 -o '[a-f0-9]\{7\}' <<< "$out")
git show --color=always "$commit" | less -R
done
fzf -e --prompt='log' --no-sort --tiebreak=index \
--preview-window=up \
--preview="git show --color=always \"\$(grep -m1 -o \"[a-f0-9]\{7\}\" <<< {})\" | less -R"
}
# }}}

git_checkout() { # {{{
local list response key branch header
list=$(git branch --all --color -vv; git tag) || return 1
mapfile -t response < <(fzf --prompt='checkout' \
mapfile -t response < <(fzf --prompt='checkout' \
--header="$header" --expect=ctrl-x <<< "$list")
key="${response[0]}"
branch=$(perl -pe 's/^\*?\s*(remotes\/[^\/]*\/)?([^ ]+).*/\2/' <<< "${response[1]}")
@@ -216,18 +214,19 @@ git_checkout() { # {{{
git_add() { # {{{
local out response query key header
header='use ctrl-p to add in patch mode'
# TODO: needs better filtering
while out=$(git ls-files -m --exclude-standard |
while out=$(git ls-files -mo --exclude-standard |
fzf --prompt='add' --tac --multi \
--header="$header" --query="$query" --print-query \
--bind=ctrl-p:accept --expect=ctrl-p)
--header="$header" --query="$query" --print-query \
--preview='git diff --color=always {} 2>&1' \
--preview-window=up \
--bind=ctrl-p:accept --expect=ctrl-p)
do
mapfile -t response <<< "$out"
query="${response[0]}" && unset response[0]
key="${response[1]}" && unset response[1]
[[ "${#response[@]}" == 0 ]] && continue
if [[ "$key" == 'ctrl-p' ]]; then
git add -p "${response[@]}";
git add -p "${response[@]}" < /dev/tty
else
git add "${response[@]}"
fi

+ 1
- 1
fzmp View File

@@ -6,7 +6,7 @@ declare -r c_red="${esc}[31m"
declare -r track_format='[[[%artist% / ][[(%date%) ]%album% / ][%track%] - [%title%]]|%file%]'

usage() {
LESS=-FEXR less <<'HELP'
LESS=-FEXR less <<HELP
fzmp [OPTIONS]

-A --all search all songs in the library (or F1 when running)

+ 7
- 3
fzmv View File

@@ -3,6 +3,9 @@
declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare dryrun verbose

set -e

err() {
echo -e "${c_red}$1${c_reset}" >&2
@@ -34,7 +37,7 @@ fzf() {

pick_files() {
local files fzpick
mapfile -t files < <(find . -maxdepth 1 2> /dev/null | sort | sed '1d; s|^\./||')
mapfile -t files < <(find . -maxdepth 1 2> /dev/null | sort -h | sed '1d; s|^\./||')
fzpick=$( for f in "${files[@]}"; do
if [[ -d "$f" ]]; then
printf '%s/\n' "$f"
@@ -55,7 +58,7 @@ pick_destination() {
while [[ "$browsedir" != "$cwd" ]]; do
dirs=$( (echo '..'; find -maxdepth 1 -type d 2> /dev/null ) |
sed 's|./||' |
sort)
sort -h)
mapfile -t browseinfo < <(
fzf --print-query \
--history="${HOME}/.cache/fzmv_history" \
@@ -77,6 +80,7 @@ pick_destination() {
while (( $# > 0 )); do
case $1 in
-t|--test) dryrun=true ;;
-v|--verbose) verbose=true ;;
esac
shift
done
@@ -84,4 +88,4 @@ done
mapfile -t files < <(pick_files)
(( ${#files[@]} > 0 )) || exit 1
destination=$(pick_destination) || exit 1
${dryrun:+echo} mv -t "$destination" "${files[@]}"
${dryrun:+echo} mv ${verbose:+-v} -t "$destination" "${files[@]}"

+ 3
- 0
ix View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash

declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare OPTIND
declare opts=()
declare id

+ 7
- 6
pkgsearch View File

@@ -8,7 +8,7 @@ declare c_blue="${esc}[34m"
declare reverse

usage() {
LESS=-EXR less <<HELP
LESS=-FEXR less <<HELP
pkgsearch [options] [query]
lists and installs packages from your distro's repositories

@@ -130,8 +130,9 @@ done
has -v fzf || die

request="$*"
if [[ -f /etc/debian_version ]]; then
debian "$request"
elif [[ -f /etc/arch-release ]]; then
arch "$request"
fi
osrelease=$(awk -F'=' '/^NAME/{gsub(/"/, "", $2); print tolower($2)}' /etc/os-release)
case "${osrelease%% *}" in
debian|ubuntu) arch "$request" ;;
arch) arch "$request" ;;
void) void "$request" ;;
esac

Loading…
Cancel
Save