Browse Source

Merge branch 'master' of ssh://gitlab.com/DanielFGray/fzf-scripts

DanielFGray 2 years ago
parent
commit
05151c4022
8 changed files with 213 additions and 196 deletions
  1. 7
    0
      README.md
  2. 42
    42
      fv
  3. 80
    75
      fzmp
  4. 18
    18
      fzmv
  5. 9
    9
      goog
  6. 21
    21
      ix
  7. 14
    14
      pkgsearch
  8. 22
    17
      sshget

+ 7
- 0
README.md View File

@@ -50,6 +50,13 @@ List and connect to wifi networks
50 50
 
51 51
 *depends on `nmcli`*
52 52
 
53
+# Install
54
+
55
+Currently there's no installation script, but if you clone the repo you can easily symlink the scripts here with something like:
56
+
57
+    cd /path/to/repo/fzf-scripts
58
+    find -maxdepth 1 -executable -type f -exec ln -s -t $HOME/.local/bin /path/to/repo/fzf-scripts/{} \;
59
+
53 60
 # Legal
54 61
 Copyright (C) 2016 Daniel F Gray <DanielFGray@gmail.com>
55 62
 

+ 42
- 42
fv View File

@@ -1,8 +1,8 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-declare esc=$(printf '\033')
4
-declare c_reset="${esc}[0m"
5
-declare c_red="${esc}[31m"
3
+declare -r esc=$'\033'
4
+declare -r c_reset="${esc}[0m"
5
+declare -r c_red="${esc}[31m"
6 6
 
7 7
 err() {
8 8
   printf "${c_red}%s${c_reset}\n" "$*" >&2
@@ -14,14 +14,14 @@ die() {
14 14
 }
15 15
 
16 16
 has() {
17
-  local verbose=false
17
+  local verbose=0
18 18
   if [[ $1 == '-v' ]]; then
19
-    verbose=true
19
+    verbose=1
20 20
     shift
21 21
   fi
22
-  for c in "$@"; do c="${c%% *}"
22
+  for c; do c="${c%% *}"
23 23
     if ! command -v "$c" &> /dev/null; then
24
-      [[ "$verbose" == true ]] && err "$c not found"
24
+      (( verbose > 0 )) && err "$c not found"
25 25
       return 1
26 26
     fi
27 27
   done
@@ -38,7 +38,7 @@ fuzzy file filtering and command executing
38 38
 HELP
39 39
 }
40 40
 
41
-setCmd() {
41
+set_cmd() {
42 42
    if has "$1"; then
43 43
     cmd="$1"
44 44
   else
@@ -48,18 +48,18 @@ setCmd() {
48 48
 
49 49
 declare cmd='vim'
50 50
 declare cmdopts=()
51
-declare searchstr=''
52
-declare searchcmd=''
53
-declare searchopts=()
51
+declare search_str=''
52
+declare search_cmd=''
53
+declare search_opts=()
54 54
 declare allfiles=0
55 55
 
56 56
 while getopts "hadlc:" opt; do
57 57
   case "$opt" in
58 58
     h) usage; exit 0        ;;
59 59
     a) allfiles=1           ;;
60
-    c) setCmd "$OPTARG"     ;;
60
+    c) set_cmd "$OPTARG"     ;;
61 61
     d) unset detach         ;;
62
-    l) searchopts+=( '-l' ) ;;
62
+    l) search_opts+=( '-l' ) ;;
63 63
   esac
64 64
 done
65 65
 shift "$((OPTIND-1))"
@@ -68,73 +68,73 @@ has -v 'fzf' || die
68 68
 
69 69
 for c in 'ag' 'ack' 'grep'; do
70 70
   if has "$c"; then
71
-    searchcmd="$c"
71
+    search_cmd="$c"
72 72
     break
73 73
   fi
74 74
 done
75 75
 
76
-if [[ $searchcmd  == 'grep' ]]; then
76
+if [[ "$search_cmd"  == 'grep' ]]; then
77 77
   err 'grep is slow, you should strongly consider installing ag or ack'
78 78
   sleep .5
79 79
 fi
80 80
 
81 81
 if [[ -n "$1" ]]; then
82 82
   if [[ -d "$1" ]]; then
83
-    searchopts+=( "$1" )
83
+    search_opts+=( "$1" )
84 84
   else
85
-    searchstr="$1"
85
+    search_str="$1"
86 86
   fi
87 87
   shift
88 88
 fi
89 89
 
90
-case "$searchcmd" in
90
+case "$search_cmd" in
91 91
   'ag')
92
-    searchopts+=( '--color' )
92
+    search_opts+=( '--color' )
93 93
     if [[ "$allfiles" == 1 ]]; then
94
-      searchopts+=( '-u' '--hidden' )
94
+      search_opts+=( '-u' '--hidden' )
95 95
     fi
96
-    if [[ "$searchstr" == '' ]]; then
97
-      searchopts+=( '-l' )
96
+    if [[ "$search_str" == '' ]]; then
97
+      search_opts+=( '-l' )
98 98
     fi
99 99
     ;;
100 100
   'ack')
101
-    if [[ "$searchstr" == '' ]]; then
101
+    if [[ "$search_str" == '' ]]; then
102 102
       if [[ "$allfiles" == 0 ]]; then
103
-        searchopts+=( '-g' '^[^\.]' )
103
+        search_opts+=( '-g' '^[^\.]' )
104 104
       else
105
-        searchopts+=( '-f' )
105
+        search_opts+=( '-f' )
106 106
       fi
107 107
     else
108
-      searchopts+=( '-l' )
109
-    #   searchopts+=( '--match' )
108
+      search_opts+=( '-l' )
109
+    #   search_opts+=( '--match' )
110 110
     fi
111 111
     ;;
112 112
   'grep')
113
-    searchopts+=( '-r' '-I' )
113
+    search_opts+=( '-r' '-I' )
114 114
     if [[ "$allfiles" == 0 ]]; then
115
-      searchopts+=( '--exclude-dir=bower_components' )
116
-      searchopts+=( '--exclude-dir=node_modules' )
117
-      searchopts+=( '--exclude-dir=jspm_packages' )
118
-      searchopts+=( '--exclude-dir=.cvs' )
119
-      searchopts+=( '--exclude-dir=.git' )
120
-      searchopts+=( '--exclude-dir=.hg' )
121
-      searchopts+=( '--exclude-dir=.svn' )
115
+      search_opts+=( '--exclude-dir=bower_components' )
116
+      search_opts+=( '--exclude-dir=node_modules' )
117
+      search_opts+=( '--exclude-dir=jspm_packages' )
118
+      search_opts+=( '--exclude-dir=.cvs' )
119
+      search_opts+=( '--exclude-dir=.git' )
120
+      search_opts+=( '--exclude-dir=.hg' )
121
+      search_opts+=( '--exclude-dir=.svn' )
122 122
     fi
123
-    if [[ "$searchstr" == '' ]]; then
124
-      searchopts+=( '' )
123
+    if [[ "$search_str" == '' ]]; then
124
+      search_opts+=( '' )
125 125
     fi
126 126
     ;;
127 127
 esac
128 128
 
129
-if [[ "$searchstr" != '' ]]; then
130
-  searchopts+=( "$searchstr" )
129
+if [[ "$search_str" != '' ]]; then
130
+  search_opts+=( "$search_str" )
131 131
 fi
132 132
 
133
-choices=$($searchcmd "${searchopts[@]}" 2> /dev/null |
133
+choices=$($search_cmd "${search_opts[@]}" 2> /dev/null |
134 134
   fzf --ansi --cycle --multi) || exit 1
135 135
 
136
-if [[ "$searchstr" != '' ]]; then
137
-  if [[ $searchcmd == 'ag' ]]; then
136
+if [[ "$search_str" != '' ]]; then
137
+  if [[ $search_cmd == 'ag' ]]; then
138 138
     choices=$(cut -d: -f1 <<< "$choices")
139 139
   fi
140 140
 fi

+ 80
- 75
fzmp View File

@@ -1,43 +1,43 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-declare -r esc=$(printf '\033')
3
+declare -r esc=$'\033'
4 4
 declare -r c_reset="${esc}[0m"
5 5
 declare -r c_red="${esc}[31m"
6 6
 declare -r config_file="${XDG_CONFIG_DIR:-$HOME/.config}/fzmp/conf"
7
+declare default_filter='filter_all_songs'
7 8
 declare track_format='[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
8
-declare filter='filterAllSongs'
9 9
 
10 10
 usage() {
11 11
   LESS=-FEXR less <<'HELP'
12 12
 fzmp [OPTIONS]
13 13
 
14
-OPTIONS:
15
-  -A --all       search all songs in the library (or F1 when running)
16
-  -a --artist    search artist then filter by album (or F2 when running)
17
-  -p --playlist  search the current playlist (or F3 when running)
18
-                 playlist view has the following keybinds:
19
-                 >   go to the next song in the playlist
20
-                 <   go to the previous song in the playlist
21
-                 C-d delete the selected songs from the playlist
22
-  -h --help      print this help
23
-
24
-CONFIGURATION:
25
-  a configuration file can be defined at $XDG_CONFIG_DIR (defaults to ~/.config)
26
-  configuration options must be defined in the format of key=value
27
-  the configuration file reads the following variables:
28
-
29
-  default_view=  must be 'artists' 'songs' or 'playlist'
30
-  format=        a format string to be passed directly to `mpc format -f`
31
-                 defaults to '[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
32
-                 for colorized output try: '[[[\e\[32m%artist%\e\[0m / ][\e\[31m[(%date%) ]%album%\e\[0m / ][\e\[34m[%track% - ][%title%]\e\[0m]]|%file%]'
33
-  fzf_options=   command line options to be passed directly to fzf
34
-                 changing this will override the default options: '+s -e -i --reverse --cycle'
35
-                 to use the jump feature of fzf you can try '+s -e -i --reverse --cycle --bind=`:jump'
36
-                 this can also be overridden with the environment variable FZMP_FZF_OPTIONS
14
+  OPTIONS:
15
+    -A --all       search all songs in the library (or F1 when running)
16
+    -a --artist    search artist then filter by album (or F2 when running)
17
+    -p --playlist  search the current playlist (or F3 when running)
18
+                   playlist view has the following keybinds:
19
+                   >   go to the next song in the playlist
20
+                   <   go to the previous song in the playlist
21
+                   C-d delete the selected songs from the playlist
22
+    -h --help      print this help
23
+
24
+  CONFIGURATION:
25
+    a configuration file can be defined at $XDG_CONFIG_DIR (defaults to ~/.config)
26
+    configuration options must be defined in the format of key=value
27
+    the configuration file reads the following variables:
28
+
29
+    default_view=      must be 'artists' 'songs' or 'playlist'
30
+    full_song_format=  a format string to be passed directly to `mpc format -f` in 'playlist' and 'all' views
31
+                       defaults to '[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
32
+                       for colorized output try: '[[[\e\[32m%artist%\e\[0m / ][\e\[31m[(%date%) ]%album%\e\[0m / ][\e\[34m[%track% - ][%title%]\e\[0m]]|%file%]'
33
+    fzf_options=       command line options to be passed directly to fzf
34
+                       changing this will override the default options: '+s -e -i --reverse --cycle'
35
+                       to use the jump feature of fzf you can try '+s -e -i --reverse --cycle --bind=`:jump'
36
+                       this can also be overridden with the environment variable FZMP_FZF_OPTIONS
37 37
 HELP
38 38
 }
39 39
 
40
-isRunning() {
40
+is_running() {
41 41
   pgrep "$1" &> /dev/null
42 42
 }
43 43
 
@@ -51,14 +51,14 @@ die() {
51 51
 }
52 52
 
53 53
 has() {
54
-  local verbose=false
54
+  local verbose=0
55 55
   if [[ $1 == '-v' ]]; then
56
-    verbose=true
56
+    verbose=1
57 57
     shift
58 58
   fi
59
-  for c in "$@"; do c="${c%% *}"
59
+  for c; do c="${c%% *}"
60 60
     if ! command -v "$c" &> /dev/null; then
61
-      [[ "$verbose" == true ]] && err "$c not found"
61
+      (( verbose > 0 )) && err "$c not found"
62 62
       return 1
63 63
     fi
64 64
   done
@@ -68,19 +68,19 @@ fzf() {
68 68
   command fzf ${FZMP_FZF_OPTIONS:-+s -e -i --reverse --cycle} --inline-info --ansi "$@"
69 69
 }
70 70
 
71
-parseConfigFile() {
72
-  local default_view format fzf_options
73
-  source "$config_file" || die 'error reading configuration file'
74
-  case "$default_view" in
75
-    playlist) filter='filterPlaylist' ;;
76
-    songs) filter='filterAllSongs' ;;
77
-    artists) filter='filterByArtist' ;;
71
+parse_config_file() {
72
+  local default_view full_song_format fzf_options
73
+  source "$config_file"
74
+  [[ -v default_view ]] && case "$default_view" in
75
+    playlist) default_filter='filter_playlist' ;;
76
+    songs) default_filter='filter_all_songs' ;;
77
+    artists) default_filter='filter_by_artist' ;;
78 78
   esac
79
-  [[ -n "$format" ]] && track_format="$format"
80
-  [[ ! -v FZMP_FZF_OPTIONS && -n "$fzf_options" ]] && FZMP_FZF_OPTIONS="$fzf_options"
79
+  [[ -v full_song_format ]] && track_format="$full_song_format"
80
+  [[ ! -v FZMP_FZF_OPTIONS && -v fzf_options ]] && FZMP_FZF_OPTIONS="$fzf_options"
81 81
 }
82 82
 
83
-filterAllSongs() {
83
+filter_all_songs() {
84 84
   local choice
85 85
   mapfile -t choice < <( mpc search -f "%file%\t$track_format" filename '' |
86 86
     fzf --multi \
@@ -89,42 +89,47 @@ filterAllSongs() {
89 89
       --expect='f2,f3,enter' |
90 90
     cut -f1)
91 91
   case "${choice[0]}" in
92
-    'f2') filterByArtist ;;
93
-    'f3') filterPlaylist ;;
94
-    'enter') printf '%s\n' "${choice[@]:1}" | playSongs ;;
92
+    'f2') filter_by_artist ;;
93
+    'f3') filter_playlist ;;
94
+    'enter') printf '%s\n' "${choice[@]:1}" | play_songs ;;
95 95
   esac
96 96
 }
97 97
 
98
-filterByArtist() {
98
+filter_by_artist() {
99 99
   local choice
100
-  mapfile -t choice < <(mpc list artist | sort -h | fzf --expect='f1,f3,enter')
100
+  mapfile -t choice < <(mpc list artist |
101
+    sort -h |
102
+    fzf \
103
+      --preview='mpc list album artist {}' \
104
+      --expect='f1,f3,enter')
101 105
   (( "${#choice[@]}" > 0 )) || die
102 106
   case "${choice[0]}" in
103
-    'f1') filterAllSongs ;;
104
-    'f3') filterPlaylist ;;
105
-    'enter') filterByAlbumFromArtist "${choice[1]}" ;;
107
+    'f1') filter_all_songs ;;
108
+    'f3') filter_playlist ;;
109
+    'enter') filter_by_album_from_artist "${choice[1]}" ;;
106 110
   esac
107 111
 }
108 112
 
109
-filterByAlbumFromArtist() {
113
+filter_by_album_from_artist() {
110 114
   local album artist choice
111
-  [[ -z "$1" ]] && filterByArtist
115
+  [[ -z "$1" ]] && filter_by_artist
112 116
   artist="$1"
113
-  mapfile -t choice < <(mpc search -f '[(%date%)\t][%album%]' artist "${artist}" |
117
+  mapfile -t choice < <(mpc search -f '[(%date%)\t][%album%]' artist "$artist" |
114 118
     sort -h | uniq |
115 119
     fzf --prompt="$artist > " \
120
+      --preview="album=\$(cut -f2 <<< {}); mpc search -f '[[[%track% - ][%title%]]|%file%]' artist \"$artist\" album \"\$album\"" \
116 121
       --expect='f1,f3,enter' \
117 122
       --bind='Ctrl-A:select-all' |
118 123
       cut -f2)
119 124
   case "${choice[0]}" in
120
-    'f1') filterAllSongs ;;
121
-    'f3') filterPlaylist ;;
122
-    'enter') filterSongsFromAlbum "$artist" "${choice[1]}" ;;
123
-    *) filterByArtist ;;
125
+    'f1') filter_all_songs ;;
126
+    'f3') filter_playlist ;;
127
+    'enter') filter_songs_from_album "$artist" "${choice[1]}" ;;
128
+    *) filter_by_artist ;;
124 129
   esac
125 130
 }
126 131
 
127
-filterSongsFromAlbum() {
132
+filter_songs_from_album() {
128 133
   local album artist choice
129 134
   [[ -z "$1" || -z "$2" ]] && die
130 135
   artist="$1"
@@ -138,14 +143,14 @@ filterSongsFromAlbum() {
138 143
       --bind='Ctrl-A:select-all' |
139 144
     cut -f1)
140 145
   case "${choice[0]}" in
141
-    'f1') filterAllSongs ;;
142
-    'f3') filterPlaylist ;;
143
-    'enter') printf '%s\n' "${choice[@]:1}" | playSongs ;;
144
-    *) filterByAlbumFromArtist "$artist" ;;
146
+    'f1') filter_all_songs ;;
147
+    'f3') filter_playlist ;;
148
+    'enter') printf '%s\n' "${choice[@]:1}" | play_songs ;;
149
+    *) filter_by_album_from_artist "$artist" ;;
145 150
   esac
146 151
 }
147 152
 
148
-filterPlaylist() {
153
+filter_playlist() {
149 154
   local choice 
150 155
   current_song=$(mpc current -f "$track_format")
151 156
   mapfile -t choice < <(mpc playlist -f "%position%\t$track_format" |
@@ -157,16 +162,16 @@ filterPlaylist() {
157 162
       --expect='f1,f2,>,<,ctrl-d,enter' |
158 163
     cut -f1) || die
159 164
   case "${choice[0]}" in
160
-    'f1') filterAllSongs ;;
161
-    'f2') filterByArtist ;;
162
-    '>') mpc -q next ; filterPlaylist ;;
163
-    '<') mpc -q prev ; filterPlaylist ;;
164
-    'ctrl-d') [[ -n "${choice[1]}" ]] && mpc -q del "${choice[@]:1}" ; filterPlaylist ;;
165
-    'enter') [[ -n "${choice[1]}" ]] && mpc -q play "${choice[@]:1}" ; filterPlaylist ;;
165
+    'f1') filter_all_songs ;;
166
+    'f2') filter_by_artist ;;
167
+    '>') mpc -q next ; filter_playlist ;;
168
+    '<') mpc -q prev ; filter_playlist ;;
169
+    'ctrl-d') [[ -n "${choice[1]}" ]] && mpc -q del "${choice[@]:1}" ; filter_playlist ;;
170
+    'enter') [[ -n "${choice[1]}" ]] && mpc -q play "${choice[@]:1}" ; filter_playlist ;;
166 171
   esac
167 172
 }
168 173
 
169
-playSongs() {
174
+play_songs() {
170 175
   mapfile -t songs
171 176
   (( "${#songs[@]}" > 0 )) || die
172 177
   printf '%s\n' "${songs[@]}" | mpc -q add
@@ -174,22 +179,22 @@ playSongs() {
174 179
   (( ${#songs[@]} > 1 )) &&
175 180
     index=$(( index - ${#songs[@]} + 1))
176 181
   mpc -q play "$index"
177
-  filterPlaylist
182
+  filter_playlist
178 183
 }
179 184
 
180
-[[ -s "$config_file" ]] && parseConfigFile
185
+[[ -s "$config_file" ]] && parse_config_file
181 186
 
182 187
 while :; do
183 188
   case "$1" in
184
-    -A|--all) filter='filterAllSongs' ; shift ;;
185
-    -a|--artist) filter='filterByArtist' ; shift ;;
186
-    -p|--playlist) filter='filterPlaylist' ; shift ;;
189
+    -A|--all) default_filter='filter_all_songs' ; shift ;;
190
+    -a|--artist) default_filter='filter_by_artist' ; shift ;;
191
+    -p|--playlist) default_filter='filter_playlist' ; shift ;;
187 192
     -h|--help) usage ; exit ;;
188 193
     *) break
189 194
   esac
190 195
 done
191 196
 
192 197
 has -v fzf mpc || die
193
-isRunning mpd || [[ -n "$MPD_HOST" ]] || die "can't connect to mpd"
198
+is_running mpd || [[ -v MPD_HOST ]] || die "can't connect to mpd"
194 199
 
195
-$filter
200
+$default_filter

+ 18
- 18
fzmv View File

@@ -1,8 +1,8 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-declare esc=$(printf '\033')
4
-declare c_reset="${esc}[0m"
5
-declare c_red="${esc}[31m"
3
+declare -r esc=$'\033'
4
+declare -r c_reset="${esc}[0m"
5
+declare -r c_red="${esc}[31m"
6 6
 declare dryrun verbose
7 7
 
8 8
 set -e
@@ -16,14 +16,14 @@ die() {
16 16
 }
17 17
 
18 18
 has() {
19
-  local verbose=false
19
+  local verbose=0
20 20
   if [[ $1 == '-v' ]]; then
21
-    verbose=true
21
+    verbose=1
22 22
     shift
23 23
   fi
24
-  for c in "$@"; do c="${c%% *}"
24
+  for c; do c="${c%% *}"
25 25
     if ! command -v "$c" &> /dev/null; then
26
-      [[ "$verbose" == true ]] && err "$c not found"
26
+      (( verbose > 0 )) && err "$c not found"
27 27
       return 1
28 28
     fi
29 29
   done
@@ -53,25 +53,25 @@ pick_files() {
53 53
 }
54 54
 
55 55
 pick_destination() {
56
-  local cwd browsedir browseinfo query dirs
56
+  local cwd browse_dir browse_info query dirs
57 57
   cwd=$(pwd)
58
-  while [[ "$browsedir" != "$cwd" ]]; do
58
+  while [[ "$browse_dir" != "$cwd" ]]; do
59 59
     dirs=$( (echo '..'; find -maxdepth 1 -type d 2> /dev/null ) |
60 60
       sed 's|./||' |
61 61
       sort -h)
62
-    mapfile -t browseinfo < <(
62
+    mapfile -t browse_info < <(
63 63
       fzf --print-query \
64 64
       --history="${HOME}/.cache/fzmv_history" \
65 65
       --header="${errors:-move files here}" <<< "$dirs")
66
-    query=${browseinfo[0]}
67
-    browsedir=${browseinfo[1]}
68
-    [[ -d "$query" ]] && browsedir="$query"
69
-    [[ ! -d "$browsedir" ]] && return 1
70
-    if [[ "$browsedir" == '.' && $(realpath "$browsedir") != "$cwd" ]]; then
71
-      realpath "$browsedir"
66
+    query=${browse_info[0]}
67
+    browse_dir=${browse_info[1]}
68
+    [[ -d "$query" ]] && browse_dir="$query"
69
+    [[ ! -d "$browse_dir" ]] && return 1
70
+    if [[ "$browse_dir" == '.' && $(realpath "$browse_dir") != "$cwd" ]]; then
71
+      realpath "$browse_dir"
72 72
       break
73 73
     else
74
-      cd "$browsedir" || die
74
+      cd "$browse_dir" || die
75 75
       continue
76 76
     fi
77 77
   done
@@ -80,7 +80,7 @@ pick_destination() {
80 80
 while (( $# > 0 )); do
81 81
   case $1 in
82 82
     -t|--test) dryrun=true ;;
83
-    -v|--verbose) verbose=true ;;
83
+    -v|--verbose) verbose=1 ;;
84 84
   esac
85 85
   shift
86 86
 done

+ 9
- 9
goog View File

@@ -1,8 +1,8 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-declare esc=$(printf '\033')
4
-declare c_reset="${esc}[0m"
5
-declare c_red="${esc}[31m"
3
+declare -r esc=$'\033'
4
+declare -r c_reset="${esc}[0m"
5
+declare -r c_red="${esc}[31m"
6 6
 
7 7
 err() {
8 8
   printf "${c_red}%s${c_reset}\n" "$*" >&2
@@ -14,14 +14,14 @@ die() {
14 14
 }
15 15
 
16 16
 has() {
17
-  local verbose=false
17
+  local verbose=0
18 18
   if [[ $1 == '-v' ]]; then
19
-    verbose=true
19
+    verbose=1
20 20
     shift
21 21
   fi
22
-  for c in "$@"; do c="${c%% *}"
22
+  for c; do c="${c%% *}"
23 23
     if ! command -v "$c" &> /dev/null; then
24
-      [[ "$verbose" == true ]] && err "$c not found"
24
+      (( verbose > 0 )) && err "$c not found"
25 25
       return 1
26 26
     fi
27 27
   done
@@ -32,10 +32,10 @@ openurl() {
32 32
   local browser
33 33
   case "$url" in
34 34
     *youtube.com*|*youtu.be*|*vimeo.com*)
35
-      browser=$(select-from \
35
+      browser=$(select_from \
36 36
         mpv mplayer2 mplayer) ;;
37 37
     *)
38
-      browser=$(select-from \
38
+      browser=$(select_from \
39 39
         -c "pgrep -u $USER -i" \
40 40
         firefox chromium-browser chrome)
41 41
       [[ ! $browser ]] && browser='w3m'

+ 21
- 21
ix View File

@@ -1,14 +1,14 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-declare esc=$(printf '\033')
4
-declare c_reset="${esc}[0m"
5
-declare c_red="${esc}[31m"
3
+declare -r esc=$'\033'
4
+declare -r c_reset="${esc}[0m"
5
+declare -r c_red="${esc}[31m"
6 6
 declare OPTIND
7 7
 declare opts=()
8 8
 declare id
9 9
 
10 10
 usage() {
11
-  more <<'HELP'
11
+  LESS=-FEXR less <<'HELP'
12 12
 ix [OPTIONS]
13 13
 
14 14
 -l             list all pastes, uses fzf for interactive use
@@ -27,22 +27,22 @@ die() {
27 27
 }
28 28
 
29 29
 has() {
30
-  local verbose=false
30
+  local verbose=0
31 31
   if [[ $1 == '-v' ]]; then
32
-    verbose=true
32
+    verbose=1
33 33
     shift
34 34
   fi
35
-  for c in "$@"; do c="${c%% *}"
35
+  for c; do c="${c%% *}"
36 36
     if ! command -v "$c" &> /dev/null; then
37
-      [[ "$verbose" == true ]] && err "$c not found"
37
+      (( verbose > 0 )) && err "$c not found"
38 38
       return 1
39 39
     fi
40 40
   done
41 41
 }
42 42
 
43
-select-from() {
43
+select_from() {
44 44
   local cmd='command -v'
45
-  for a in "$@"; do
45
+  for a; do
46 46
     case "$a" in
47 47
       -c)
48 48
         cmd="$2"
@@ -50,7 +50,7 @@ select-from() {
50 50
         ;;
51 51
     esac
52 52
   done
53
-  for c in "$@"; do
53
+  for c; do
54 54
     if $cmd "${c%% *}" &> /dev/null; then
55 55
       echo "$c"
56 56
       return 0
@@ -59,11 +59,11 @@ select-from() {
59 59
   return 1
60 60
 }
61 61
 
62
-hasAccount() {
62
+has_account() {
63 63
   grep -qF 'ix.io' ~/.netrc
64 64
 }
65 65
 
66
-createAccount() {
66
+create_account() {
67 67
   echo "It seems you don't have a ~/.netrc with ix.io in it. Let's make one!"
68 68
   read -r -p 'enter a username: ' username
69 69
   read -rs -p 'enter a password (this will be hashed with sha256sum): ' password
@@ -74,11 +74,11 @@ createAccount() {
74 74
   echo "$username"
75 75
 }
76 76
 
77
-getUserName() {
77
+get_user_name() {
78 78
   awk '"ix.io"==$2{print $4}' ~/.netrc
79 79
 }
80 80
 
81
-getPastes() {
81
+get_pastes() {
82 82
   curl -s "http://ix.io/user/$1" |
83 83
     grep -A1 -P '\<a href="\/[a-zA-Z0-9]+"\>' |
84 84
     awk -F'--' '
@@ -88,13 +88,13 @@ getPastes() {
88 88
     '
89 89
 }
90 90
 
91
-listPastes() {
91
+list_pastes() {
92 92
   local highlighter
93
-  highlighter=$(select-from pygmentize 'highlight -q --force -O ansi')
94
-  getPastes "$(getUserName)" | fzf \
93
+  highlighter=$(select_from 'highlight -q --force -O ansi' pygmentize)
94
+  get_pastes "$(get_user_name)" | fzf \
95 95
     --inline-info --cycle \
96 96
     --header='Ctrl-E = edit; Ctrl-V = view; Ctrl-D = delete' \
97
-    --preview="p={}; curl -s \"\${p## *}\" ${highlighter:+ | $highlighter}" \
97
+    --preview="p={}; curl -s \"\${p## *}\" | head -n\$LINES ${highlighter:+ | $highlighter}" \
98 98
     --bind 'space:jump' \
99 99
     --bind 'j:down' --bind 'k:up' \
100 100
     --bind 'q:abort' \
@@ -105,7 +105,7 @@ listPastes() {
105 105
 
106 106
 has -v curl || die
107 107
 
108
-hasAccount || createAccount
108
+has_account || create_account
109 109
 
110 110
 [[ -e ~/.netrc ]] && opts+=( '-n' )
111 111
 
@@ -115,7 +115,7 @@ while getopts ":hld:i:n:" x; do
115 115
     d) curl "${opts[@]}" -X DELETE "ix.io/$OPTARG"; exit ;;
116 116
     l)
117 117
       if [[ -z "$OPTARG" && -e ~/.netrc ]]; then
118
-        listPastes | awk '{print $2}' | tee /dev/tty | xclip
118
+        list_pastes | awk '{print $2}' | tee /dev/tty | xclip
119 119
       else
120 120
         die 'no netrc found'
121 121
       fi

+ 14
- 14
pkgsearch View File

@@ -1,10 +1,10 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-declare esc=$(printf '\033')
4
-declare c_reset="${esc}[0m"
5
-declare c_red="${esc}[31m"
6
-declare c_green="${esc}[32m"
7
-declare c_blue="${esc}[34m"
3
+declare -r esc=$'\033'
4
+declare -r c_reset="${esc}[0m"
5
+declare -r c_red="${esc}[31m"
6
+declare -r c_green="${esc}[32m"
7
+declare -r c_blue="${esc}[34m"
8 8
 declare reverse
9 9
 
10 10
 usage() {
@@ -29,22 +29,22 @@ die() {
29 29
 }
30 30
 
31 31
 has() {
32
-  local verbose=false
32
+  local verbose=0
33 33
   if [[ $1 == '-v' ]]; then
34
-    verbose=true
34
+    verbose=1
35 35
     shift
36 36
   fi
37
-  for c in "$@"; do c="${c%% *}"
37
+  for c; do c="${c%% *}"
38 38
     if ! command -v "$c" &> /dev/null; then
39
-      [[ "$verbose" == true ]] && err "$c not found"
39
+      (( "$verbose" > 0 )) && err "$c not found"
40 40
       return 1
41 41
     fi
42 42
   done
43 43
 }
44 44
 
45
-select-from() {
45
+select_from() {
46 46
   local cmd='command -v'
47
-  for a in "$@"; do
47
+  for a; do
48 48
     case "$a" in
49 49
       -c)
50 50
         cmd="$2"
@@ -52,7 +52,7 @@ select-from() {
52 52
         ;;
53 53
     esac
54 54
   done
55
-  for c in "$@"; do
55
+  for c; do
56 56
     if $cmd "${c%% *}" &> /dev/null; then
57 57
       echo "$c"
58 58
       return 0
@@ -74,7 +74,7 @@ install() {
74 74
   (( ${#pkgs} > 0 )) || exit
75 75
   count="${#pkgs[@]} package"
76 76
   (( ${#pkgs[@]} > 1 )) && count+='s'
77
-  echo "installing ${count}: ${pkgs[*]}"
77
+  printf "installing %s: %s\n" "$count" "${pkgs[*]}"
78 78
   $1 "${pkgs[@]}" < /dev/tty
79 79
 }
80 80
 
@@ -86,7 +86,7 @@ debian() {
86 86
     < <(apt-cache search '' | sort |
87 87
       sed -u -r "s|^([^ ]+)|${c_green}\1${c_reset}|") |
88 88
     cut -d' ' -f1 |
89
-    install "sudo $(select-from 'apt' 'aptitude' 'apt-get') install"
89
+    install "sudo $(select_from 'apt' 'aptitude' 'apt-get') install"
90 90
 }
91 91
 
92 92
 arch() {

+ 22
- 17
sshget View File

@@ -1,20 +1,14 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
+declare -r esc=$'\033'
4
+declare -r c_reset="${esc}[0m"
5
+declare -r c_red="${esc}[31m"
6
+
3 7
 declare -r fifo='/tmp/sshget.fifo'
4 8
 declare -A domains=()
5 9
 declare -A paths=()
6 10
 declare -a files=()
7 11
 
8
-declare esc=$(printf '\033')
9
-declare c_reset="${esc}[0m"
10
-declare c_red="${esc}[31m"
11
-
12
-usage() {
13
-  more <<'HELP'
14
-sshget user@host1:/path/to/search user@host2:/path/to/search
15
-HELP
16
-}
17
-
18 12
 err() {
19 13
   printf "${c_red}%s${c_reset}\n" "$*" >&2
20 14
 }
@@ -23,15 +17,21 @@ die() {
23 17
   exit 1
24 18
 }
25 19
 
20
+usage() {
21
+  LESS=-FEXR less <<'HELP'
22
+sshget <user@host1:/path/to/search ...>
23
+HELP
24
+}
25
+
26 26
 has() {
27
-  local verbose=false
27
+  local verbose=0
28 28
   if [[ $1 == '-v' ]]; then
29
-    verbose=true
29
+    verbose=1
30 30
     shift
31 31
   fi
32
-  for c in "$@"; do c="${c%% *}"
32
+  for c; do c="${c%% *}"
33 33
     if ! command -v "$c" &> /dev/null; then
34
-      [[ "$verbose" == true ]] && err "$c not found"
34
+      (( verbose > 0 )) && err "$c not found"
35 35
       return 1
36 36
     fi
37 37
   done
@@ -46,8 +46,13 @@ trap cleanup SIGHUP SIGINT SIGTERM
46 46
 
47 47
 mkfifo "$fifo"
48 48
 
49
-for a in "$@"; do
50
-  host="${a%%:*}"
49
+if (( $# < 1 )); then
50
+  usage
51
+  die
52
+fi
53
+
54
+for a; do
55
+  host="${a%:*}"
51 56
   path="${a##*:}"
52 57
   domains+=( ["$a"]="$host" )
53 58
   paths+=( ["$a"]="$path" )
@@ -55,7 +60,7 @@ for a in "$@"; do
55 60
 done
56 61
 
57 62
 for s in "${!domains[@]}"; do
58
-  ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^(.*)|${domains[$s]}:\"\1\"|" >> "$fifo" &
63
+  ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
59 64
 done
60 65
 
61 66
 mapfile -t files < <( fzf -e --inline-info --multi --cycle < "$fifo" )

Loading…
Cancel
Save