Browse Source

more colors

DanielFGray 11 months ago
parent
commit
8d6eb89ffe
10 changed files with 133 additions and 72 deletions
  1. 16
    2
      fzgit
  2. 17
    17
      fzmp
  3. 18
    17
      fzmv
  4. 39
    16
      gitup
  5. 6
    2
      ix
  6. 6
    10
      npmsearch
  7. 23
    3
      pkgrm
  8. 6
    3
      pkgsearch
  9. 1
    1
      pkgup
  10. 1
    1
      sshget

+ 16
- 2
fzgit View File

@@ -41,7 +41,13 @@ fzf() { # {{{
41 41
     shift
42 42
   fi
43 43
   branch=$(git status 2> /dev/null | sed 's/On branch />/;q')
44
-  command fzf --inline-info --ansi --cycle --prompt="fzgit${branch}>${prompt} " "$@"
44
+  opts=( +s -e -i --reverse --cycle --prompt="fzgit${branch}>${prompt} " )
45
+  [[ -v FZMP_FZF_OPTIONS ]] && opts=( $FZMP_FZF_OPTIONS )
46
+  command fzf "${opts[@]}" \
47
+    --inline-info \
48
+    --ansi \
49
+    --no-clear \
50
+    "$@"
45 51
 }
46 52
 # }}}
47 53
 
@@ -192,7 +198,6 @@ declare -A implemented_git_cmds=(
192 198
 git_log() { # {{{
193 199
   local show="git show --color=always \"\$(grep -m1 -o \"[a-f0-9]\{7\}\" <<< {})\""
194 200
   fzf --prompt='log' -e --no-sort --tiebreak=index \
195
-    --preview-window=up \
196 201
     --bind="enter:execute:$show | less -R" \
197 202
     --preview="$show" \
198 203
   < <(git log --graph --color=always \
@@ -276,4 +281,13 @@ main() {
276 281
   done
277 282
 }
278 283
 
284
+reset_screen() {
285
+  tput rmcup
286
+}
287
+
288
+finish() {
289
+  reset_screen
290
+}
291
+
292
+trap finish EXIT SIGINT SIGTERM
279 293
 main

+ 17
- 17
fzmp View File

@@ -9,13 +9,12 @@ OPTIONS:
9 9
     search all songs in the library (or F1 when running)
10 10
   -a --artist
11 11
     search artist then filter by album (or F2 when running)
12
-    
13 12
   -p --playlist
14 13
     search the current playlist (or F3 when running)
15 14
     playlist view has the following keybinds:
16
-    >   go to the next song in the playlist
17
-    <   go to the previous song in the playlist
18
-    C-d delete the selected songs from the playlist
15
+    >       go to the next song in the playlist
16
+    <       go to the previous song in the playlist
17
+    Ctrl-d  delete the selected songs from the playlist
19 18
   -g --genre
20 19
     list genres (or F4 when running)
21 20
   -h --help
@@ -34,23 +33,23 @@ CONFIGURATION:
34 33
     [[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]
35 34
     For colorized output try:
36 35
     [[[\e\[32m%artist%\e\[0m / ][\e\[31m[(%date%) ]%album%\e\[0m / ][\e\[34m[%track% - ][%title%]\e\[0m]]|%file%]
37
-  playlist_view_key
38
-  track_view_key
39
-  artist_view_key
40
-  genre_view_key
36
+  playlist_view_key (default F1)
37
+  track_view_key (default F2)
38
+  artist_view_key (default F3)
39
+  genre_view_key (default F4)
41 40
     allows customizing which keys fire the different views
42 41
   findadd_key
43
-    adds all songs by artist/genre/album
44
-    defaults to Ctrl-x
42
+    adds all songs under the cursor by artist/genre/album
43
+    defaults to ctrl-space
45 44
   fzf_options
46 45
     Command line options to be passed directly to fzf.
47 46
     Changing this will override the default options: +s -e -i --reverse --cycle
48 47
     To use the jump feature of fzf you can try:
49 48
     +s -e -i --reverse --cycle --bind=`:jump
50
-    or add this to your FZF_DEFAULT_OPTS
51 49
     It also helps to have a bind for toggle-all, e.g.
52
-    +s -e -i --reverse --cycle --bind=`:jump --bind="Ctrl-A:toggle-all"
53
-    This can also be overridden with the environment variable FZMP_FZF_OPTIONS
50
+    +s -e -i --reverse --cycle --bind=`:jump --bind="ctrl-t:toggle-all"
51
+    individual sessions also override with the environment variable FZMP_FZF_OPTIONS
52
+    fzmp will also inherit options from FZF_DEFAULT_OPTS
54 53
 HELP
55 54
 }
56 55
 
@@ -67,7 +66,7 @@ bindings=(
67 66
   [track]='f2'
68 67
   [artist]='f3'
69 68
   [genre]='f4'
70
-  [findadd]='ctrl-x'
69
+  [findadd]='ctrl-space'
71 70
 )
72 71
 
73 72
 do_binding() {
@@ -182,6 +181,7 @@ parse_config_file() {
182 181
     esac
183 182
   done < "$config_file"
184 183
   IFS=',' key_bindings="${bindings[*]}"
184
+  key_bindings="${key_bindings/,${bindings[findadd]}}"
185 185
   findadd_key="${bindings[findadd]}"
186 186
   if (( ${#config_err[@]} > 0 )); then
187 187
     err 'there were errors parsing config file:'
@@ -218,7 +218,7 @@ filter_by_genres() {
218 218
   (( ${#choice[@]} > 0 )) || die
219 219
   case "${choice[0]}" in
220 220
     enter) filter_by_artist_from_genre "${choice[1]}" ;;
221
-    *) do_binding "${choice[0]}" || exit ;;
221
+    *) do_binding "${choice[0]}" || "$default_filter" ;;
222 222
   esac
223 223
 }
224 224
 
@@ -272,7 +272,7 @@ filter_by_album_from_artist() {
272 272
 
273 273
 filter_songs_from_album() {
274 274
   local album artist choice
275
-  [[ -z "$1" || -z "$2" ]] && die
275
+  [[ -z "$1" || -z "$2" ]] && exit 999
276 276
   artist="$1"
277 277
   album="$2"
278 278
   mapfile -t choice < <(mpc search -f '%file%\t[[[%track% - ][%title%]]|%file%]' artist "${artist}" album "${album}" |
@@ -280,7 +280,7 @@ filter_songs_from_album() {
280 280
       --multi \
281 281
       --with-nth='2..' \
282 282
       --delimiter='\t' \
283
-      --expect='f1,f2,f3,enter' |
283
+      --expect="${key_bindings},enter" |
284 284
     cut -f1)
285 285
   case "${choice[0]}" in
286 286
     'enter') printf '%s\n' "${choice[@]:1}" | add_songs play ;;

+ 18
- 17
fzmv View File

@@ -37,34 +37,35 @@ fzf() {
37 37
 
38 38
 pick_files() {
39 39
   local files fzpick
40
-  mapfile -t files < <(find . -maxdepth 1 2> /dev/null | sort -h | sed '1d; s|^\./||')
41
-  fzpick=$( for f in "${files[@]}"; do
42
-    if [[ -d "$f" ]]; then
43
-      printf '%s/\n' "$f"
44
-    elif [[ -L "$f" ]]; then
45
-      printf '%s@\n' "$f"
46
-    else
47
-      printf '%s\n' "$f"
48
-    fi
49
-  done | fzf --multi --header='move these files' ) || return 1
50
-  for f in "${fzpick[@]}"; do
51
-    realpath -s "$f"
52
-  done
40
+  find . -maxdepth 1 2> /dev/null |
41
+    sort -h |
42
+    sed '1d; s|^\./||' |
43
+    while read -r f; do
44
+      if [[ -d "$f" ]]; then
45
+        printf '%s/\n' "$f"
46
+      elif [[ -L "$f" ]]; then
47
+        printf '%s@\n' "$f"
48
+      else
49
+        printf '%s\n' "$f"
50
+      fi
51
+    done |
52
+    fzf --multi --header='move these files'  || return 1
53 53
 }
54 54
 
55 55
 pick_destination() {
56 56
   local cwd browse_dir browse_info query dirs
57 57
   cwd=$(pwd)
58 58
   while [[ "$browse_dir" != "$cwd" ]]; do
59
-    dirs=$( (echo '..'; find -maxdepth 1 -type d 2> /dev/null ) |
60
-      sed 's|./||' |
61
-      sort -h)
62 59
     mapfile -t browse_info < <(
60
+    { echo '..'; find . -maxdepth 1 -type d 2> /dev/null; } |
61
+      sed 's|^./||' |
62
+      sort -h |
63 63
       fzf --print-query \
64 64
       --history="${HOME}/.cache/fzmv_history" \
65
-      --header="${errors:-move files here}" <<< "$dirs")
65
+      --header="${errors:-move files here}")
66 66
     query=${browse_info[0]}
67 67
     browse_dir=${browse_info[1]}
68
+    files=( "${browse_info[@]:2}" )
68 69
     [[ -d "$query" ]] && browse_dir="$query"
69 70
     [[ ! -d "$browse_dir" ]] && return 1
70 71
     if [[ "$browse_dir" == '.' && $(realpath "$browse_dir") != "$cwd" ]]; then

+ 39
- 16
gitup View File

@@ -7,21 +7,29 @@ colors[blue]=$(tput setaf 4)
7 7
 colors[reset]=$(tput sgr0)
8 8
 declare processes=4
9 9
 declare quiet
10
+declare force
10 11
 declare -a dirs
12
+declare -a ignore_dir
13
+declare -a ignore_dirs
14
+declare -a errs
11 15
 
12 16
 usage() {
13 17
   LESS=-FEXR less <<'HELP'
14
-gitup [dir] [OPTIONS]
18
+gitup [OPTIONS] [dirs]
15 19
 
16 20
 search for git repos and update them
17 21
 
18 22
 if unspecified, dir defaults to $HOME
19 23
 
20
--p [number]    how many processes to run git pull in parallel
21
--q             quiet level, may be stacked
22
-               first level suppresses output from `git pull`
23
-               second level suppresses job info
24
--h             print this help
24
+  -i [dir]       comma separated list of directory paths to not search
25
+  -p [number]    how many processes to run `git pull` in parallel
26
+  -q             quiet level, may be stacked
27
+                 first level suppresses output from `git pull`
28
+                 second level suppresses job info
29
+  -F             don't run interactively, `git pull` all dirs
30
+                 use with caution, make sure you know which dirs will be matched
31
+                 works best if gitup is provided a list of dirs known to have git repos
32
+  -h             print this help
25 33
 HELP
26 34
 }
27 35
 
@@ -29,9 +37,9 @@ color() {
29 37
   local c
30 38
   c="$1"
31 39
   shift
32
-  printf '%s' "${colors[$c]}" >&2
33
-  printf '%s\n' "$@" >&2
34
-  printf '%s' "${colors[reset]}" >&2
40
+  printf '%s' "${colors[$c]}"
41
+  printf '%s\n' "$@"
42
+  printf '%s' "${colors[reset]}"
35 43
 }
36 44
 
37 45
 err() {
@@ -59,11 +67,13 @@ has() {
59 67
 
60 68
 has -v fzf git || die
61 69
 
62
-while getopts ":hqp:" x; do
70
+while getopts ':hqp:i:F' x; do o="$OPTARG"
63 71
   case "$x" in
64 72
     h) usage; exit; ;;
65
-    p) processes="$OPTARG" ;;
66
-    q) (( quiet++ )) ;;
73
+    p) processes="$o" ;;
74
+    q) (( ++quiet )) ;;
75
+    i) IFS=',' read -ra ignore_dir <<< "$o" ;;
76
+    F) (( ++force )) ;;
67 77
   esac
68 78
 done
69 79
 shift $(( OPTIND - 1 ))
@@ -75,10 +85,19 @@ while :; do
75 85
   shift || break
76 86
 done
77 87
 
88
+for o in "${ignore_dir[@]}"; do
89
+  ignore_dirs+=( -path "*/$o" -o  )
90
+done
91
+
78 92
 (( ${#dirs[@]} > 0 )) || dirs=("$HOME")
79 93
 
80
-mapfile -t repos < <(find -L "${dirs[@]}" -name '.git' -printf '%h\n' 2> /dev/null \
81
-  | fzf --multi --cycle --inline-info)
94
+mapfile -t repos < <(find "${dirs[@]}"  \
95
+  \( "${ignore_dirs[@]}" \
96
+    -fstype 'devfs' \
97
+    -o -fstype 'devtmpfs' \
98
+    -o -fstype 'proc' \
99
+  \) -prune -o -name '.git' -printf '%h\n' 2> /dev/null |
100
+  fzf --multi --cycle --inline-info +s -e ${force:+-f /})
82 101
 
83 102
 (( ${#repos[@]} > 0 )) || exit
84 103
 
@@ -90,7 +109,7 @@ update() {
90 109
   if git -C "$dir" pull ${quiet:+-q}; then
91 110
     (( quiet > 1 )) || color green ":: updated $name"
92 111
   else
93
-    color red ":: failed to update $name"
112
+    errs+=( "$name" )
94 113
   fi
95 114
 }
96 115
 
@@ -100,4 +119,8 @@ for d in "${repos[@]}"; do
100 119
 done
101 120
 wait
102 121
 
103
-printf '%d repos updated\n' "${#repos[@]}"
122
+if (( "${#errs[@]}" > 0 )); then
123
+  color red 'The following packages failed to update:'
124
+  color red "  ${errs[*]}"
125
+fi
126
+color green "updated ${#repos[@]} repos"

+ 6
- 2
ix View File

@@ -106,7 +106,10 @@ list_pastes() {
106 106
   if [[ -n "$url" ]]; then
107 107
     mapfile -t res <<< "$url"
108 108
     if [[ "${res[0]}" = 'Ctrl-D' ]]; then
109
-      ix -d "${res[1]}"
109
+      id="${res[1]}"
110
+      id="${id#*ix.io/}"
111
+      id="${id%%$'\t'*}"
112
+      ix -d "$id"
110 113
       list_pastes
111 114
       exit
112 115
     fi
@@ -125,7 +128,8 @@ while getopts ":hld:i:n:" x; do
125 128
     d) curl -s "${opts[@]}" -X DELETE "$OPTARG"; exit ;;
126 129
     l)
127 130
       if [[ -e ~/.netrc ]]; then
128
-        list_pastes | cut -d' ' -f1 | xclip
131
+        url=$(list_pastes)
132
+        [[ -n "$url" ]] && cut -f1 <<< "$url" | tee | xclip
129 133
       else
130 134
         die 'no netrc found'
131 135
       fi

+ 6
- 10
npmsearch View File

@@ -8,7 +8,6 @@ declare global=0
8 8
 declare -A colors
9 9
 colors[red]=$(tput setaf 1)
10 10
 colors[green]=$(tput setaf 2)
11
-colors[blue]=$(tput setaf 4)
12 11
 colors[reset]=$(tput sgr0)
13 12
 
14 13
 color() {
@@ -26,7 +25,7 @@ die() {
26 25
 }
27 26
 
28 27
 has() {
29
-  local v=0
28
+  local v c
30 29
   if [[ $1 = '-v' ]]; then
31 30
     v=1
32 31
     shift
@@ -43,10 +42,7 @@ select_from() {
43 42
   local cmd='command -v'
44 43
   for a; do
45 44
     case "$a" in
46
-      -c)
47
-        cmd="$2"
48
-        shift 2
49
-        ;;
45
+      -c) cmd="$2"; shift 2 ;;
50 46
     esac
51 47
   done
52 48
   for c; do
@@ -72,7 +68,7 @@ if [[ $1 = '-r' || $1 = '--remove' ]]; then
72 68
   die
73 69
 fi
74 70
 
75
-printf 'searching...\r'
71
+printf '%ssearching...%s\r' "${colors[green]}" "${colors[reset]}"
76 72
 search=$(npm search --json "$*") || exit
77 73
 
78 74
 search=$(jq -r '.[] | "\(.name)|\(.version)|\(.description)"' <<< "$search" | column -t -s'|')
@@ -87,7 +83,7 @@ mapfile -t packages < <(fzf --multi \
87 83
 
88 84
 key="${packages[0]}"
89 85
 case "${key,,}" in
90
-  esc) die 'cancelled' ;;
86
+  esc) die ;;
91 87
   ctrl-d) savedev=1 ;;
92 88
   ctrl-g) global=1 ;;
93 89
   ctrl-v)
@@ -98,7 +94,7 @@ case "${key,,}" in
98 94
         fzf --header="choose version for $package  |  C-d saves as devDependency" --tac --expect='ctrl-d,esc')
99 95
     key="${version[0]}"
100 96
     case "${key,,}" in
101
-      esc) die 'cancelled' ;;
97
+      esc) die ;;
102 98
       ctrl-d) savedev=1 ;;
103 99
     esac
104 100
     packages=( "${package}@${version[1]}" )
@@ -112,7 +108,7 @@ if (( ${#packages[@]} > 1 )); then
112 108
   packages=( "${packages[@]%% *}" )
113 109
 fi
114 110
 
115
-printf "installing...\r"
111
+printf '%sinstalling...%s\r' "${colors[green]}" "${colors[reset]}"
116 112
 if (( global > 0 )); then
117 113
   npm install -g "${args[@]}" "${packages[@]}"
118 114
 elif has yarn; then

+ 23
- 3
pkgrm View File

@@ -25,7 +25,25 @@ die() {
25 25
   exit 1
26 26
 }
27 27
 
28
-has -v fzf || die
28
+select_from() {
29
+  local o c cmd OPTARG OPTIND
30
+  cmd='command -v'
31
+  while getopts 'c:' o; do
32
+    case "$o" in
33
+      c) cmd="$OPTARG" ;;
34
+    esac
35
+  done
36
+  shift "$((OPTIND-1))"
37
+  for c; do
38
+    if $cmd "${c%% *}" &> /dev/null; then
39
+      echo "$c"
40
+      return 0
41
+    fi
42
+  done
43
+  return 1
44
+}
45
+
46
+has -v fzf expac || die
29 47
 
30 48
 fzf() {
31 49
   command fzf -e --multi --no-hscroll --inline-info --cycle --bind='Ctrl-a:toggle-all' "$@"
@@ -40,10 +58,12 @@ if (( $# > 0 )); then
40 58
   exit
41 59
 fi
42 60
 
61
+preview=$(select_from pacaur pacman)
62
+
43 63
 if (( by_size )); then
44
-  mapfile -t pkgs < <(expac -H M '%m\t%n' | sort -hr | fzf --preview='pacman -Si {3}' -q '!^lib ' | cut -f2)
64
+  mapfile -t pkgs < <(expac -H M '%m\t%n' | sort -hr | fzf +s --preview="$preview --color=always -Si {3}" -q '!^lib ' | cut -f2)
45 65
 else
46
-  mapfile -t pkgs < <(expac '%n' | fzf --preview='pacman -Si {1}' -q '!^lib ' | cut -d' ' -f1)
66
+  mapfile -t pkgs < <(expac '%n' | fzf +s --preview="$preview --color=always -Si {1}" -q '!^lib ' | cut -d' ' -f1)
47 67
 fi
48 68
 
49 69
 (( ${#pkgs[@]} > 0 )) && sudo pacman -Rcusn "${pkgs[@]}"

+ 6
- 3
pkgsearch View File

@@ -88,7 +88,7 @@ debian() {
88 88
 arch() {
89 89
   local search packages
90 90
   search='pacman'
91
-  [[ -n "$1" ]] && search=$(select_from 'pacaur' 'yaourt' 'packer' 'apacman' 'pacman')
91
+  [[ -n "$1" ]] && search=$(select_from 'pacaur' 'trizen' 'yaourt' 'packer' 'apacman' 'pacman')
92 92
   packages=$(fzf --preview="$search -Si {2}" \
93 93
     < <( $search -Ss "$1" |
94 94
       gawk '{
@@ -114,8 +114,8 @@ void() {
114 114
 }
115 115
 
116 116
 fedora() {
117
-  fzf --preview='p={}; p="${p%% *}"; dnf -q info "${p%.*}"' \
118
-    < <(dnf -qC repoquery --qf "${c_green}%{name} ${c_reset}%{version} - %{summary}" \*) |
117
+  fzf --query="$*" --preview='p={}; p="${p%% *}"; dnf -q info "${p%.*}"' \
118
+    < <(dnf -qC repoquery --qf "${c_green}%{name} ${c_reset} - %{summary}" \*) |
119 119
     awk '{ package=$1; sub(/\.\S+/, "", package); print package }' |
120 120
     install 'sudo dnf install'
121 121
 }
@@ -144,3 +144,6 @@ case "$distro" in
144 144
   fedora) fedora "$request" ;;
145 145
   *) die 'unknown distro :(' ;;
146 146
 esac
147
+
148
+# TODO: homebrew: brew desc -s
149
+# sample output: https://pastebin.com/raw/3frRf6C7

+ 1
- 1
pkgup View File

@@ -44,7 +44,7 @@ select_from() {
44 44
 
45 45
 has -v fzf || die
46 46
 
47
-helper=$(select_from 'pacaur' 'yaourt' 'packer' 'apacman' 'pacman')
47
+helper=$(select_from pacaur trizen packer apacman pacman)
48 48
 
49 49
 mapfile -t pkgs < <(
50 50
   $helper -Qu --color=always |

+ 1
- 1
sshget View File

@@ -63,7 +63,7 @@ for s in "${!domains[@]}"; do
63 63
   ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
64 64
 done
65 65
 
66
-mapfile -t files < <( fzf -e --inline-info --multi --cycle --bind='Ctrl-A:toggle-all,`:jump' < "$fifo" )
66
+mapfile -t files < <(fzf -e --inline-info +s --multi --cycle --bind='Ctrl-A:toggle-all,`:jump' < "$fifo")
67 67
 
68 68
 if (( ${#files[@]} )); then
69 69
   rsync --protect-args -auvzP -e ssh "${files[@]}" .

Loading…
Cancel
Save