Browse Source

update fzmp: docs and prompt

DanielFGray 1 year ago
parent
commit
58844f41df
1 changed files with 60 additions and 28 deletions
  1. 60
    28
      fzmp

+ 60
- 28
fzmp View File

@@ -4,35 +4,64 @@ usage() {
4 4
   LESS=-FEXR less <<'HELP'
5 5
 fzmp [OPTIONS]
6 6
 
7
-  OPTIONS:
8
-    -A --all       search all songs in the library (or F1 when running)
9
-    -a --artist    search artist then filter by album (or F2 when running)
10
-    -p --playlist  search the current playlist (or F3 when running)
11
-                   playlist view has the following keybinds:
12
-                   >   go to the next song in the playlist
13
-                   <   go to the previous song in the playlist
14
-                   C-d delete the selected songs from the playlist
15
-    -h --help      print this help
7
+OPTIONS:
8
+  -A --all
9
+    search all songs in the library (or F1 when running)
10
+  -a --artist
11
+    search artist then filter by album (or F2 when running)
12
+  -p --playlist
13
+    search the current playlist (or F3 when running)
14
+    playlist view has the following keybinds:
15
+    >   go to the next song in the playlist
16
+    <   go to the previous song in the playlist
17
+    C-d delete the selected songs from the playlist
18
+  -h --help
19
+    print this help
16 20
 
17
-  CONFIGURATION:
18
-    A configuration file can be defined at $XDG_CONFIG_DIR (defaults to ~/.config)
19
-    If a line begins with '#' it is treated as a comment and ignored
20
-    The configuration file reads the following options:
21
+CONFIGURATION:
22
+  A configuration file can be defined at $XDG_CONFIG_DIR (defaults to ~/.config)
23
+  If a line begins with '#' it is treated as a comment and ignored
24
+  The configuration file reads the following options:
21 25
 
22
-    default_view       must be 'artists' 'songs' or 'playlist'
23
-    full_song_format   a format string to be passed directly to `mpc format -f` in 'playlist' and 'all' views
24
-                       defaults to '[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
25
-                       for colorized output try: '[[[\e\[32m%artist%\e\[0m / ][\e\[31m[(%date%) ]%album%\e\[0m / ][\e\[34m[%track% - ][%title%]\e\[0m]]|%file%]'
26
-    fzf_options        command line options to be passed directly to fzf
27
-                       changing this will override the default options: '+s -e -i --reverse --cycle'
28
-                       to use the jump feature of fzf you can try '+s -e -i --reverse --cycle --bind=`:jump'
29
-                       this can also be overridden with the environment variable FZMP_FZF_OPTIONS
26
+  default_view
27
+    Must be 'artists' 'songs' 'playlist' or 'genres'
28
+  full_song_format
29
+    A format string to be passed directly to `mpc format -f` in
30
+    'playlist' and 'all' views. Defaults to:
31
+    [[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]
32
+    For colorized output try:
33
+    [[[\e\[32m%artist%\e\[0m / ][\e\[31m[(%date%) ]%album%\e\[0m / ][\e\[34m[%track% - ][%title%]\e\[0m]]|%file%]
34
+  playlist_view_key
35
+    shows the playlist from any view
36
+    defaults to f1
37
+  track_view_key
38
+    shows all tracks from any view
39
+    defaults to f2
40
+  artist_view_key
41
+    shows artists from any view
42
+    defaults to f3
43
+  genre_view_key
44
+    shows genres from any view
45
+    defaults to f4
46
+  findadd_key
47
+    adds all songs by artist/genre/album
48
+    defaults to Ctrl-x
49
+  fzf_options
50
+    Command line options to be passed directly to fzf.
51
+    Changing this will override the default options: +s -e -i --reverse --cycle
52
+    To use the jump feature of fzf you can try:
53
+    +s -e -i --reverse --cycle --bind=`:jump
54
+    or add this to your FZF_DEFAULT_OPTS
55
+    It also helps to have a bind for toggle-all, e.g.
56
+    +s -e -i --reverse --cycle --bind=`:jump --bind="Ctrl-A:toggle-all"
57
+    This can also be overridden with the environment variable FZMP_FZF_OPTIONS
30 58
 HELP
31 59
 }
32 60
 
33 61
 declare -r config_file="${XDG_CONFIG_DIR:-$HOME/.config}/fzmp/conf"
34 62
 declare default_filter='filter_by_playlist'
35 63
 declare track_format='[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
64
+declare -r album_listing="mpc search -f '%album%\t%title%' artist {} | awk -F'\t' '{ if(album != \$1) { album=\$1; print album } printf \"  %s\n\", \$2 }'"
36 65
 declare -a config_err
37 66
 
38 67
 declare playlist_view_key='f1'
@@ -110,11 +139,12 @@ parse_config_file() {
110 139
       full_song_format) track_format="$val" ;;
111 140
       fzf_options) [[ ! -v FZMP_FZF_OPTIONS ]] && FZMP_FZF_OPTIONS="$val" ;;
112 141
       default_view)
113
-        if [[ "$val" =~ playlist|songs|artists ]]; then
142
+        if [[ "$val" =~ ^playlist$|^songs$|^artists$|^genres$ ]]; then
114 143
           case "$val" in
115 144
             playlist) default_filter='filter_by_playlist' ;;
116 145
             songs) default_filter='filter_all_songs' ;;
117 146
             artists) default_filter='filter_by_artist' ;;
147
+            genres) default_filter='filter_by_genre' ;;
118 148
           esac
119 149
         else
120 150
           config_err+=( "unknown format \"$val\" in config file on line $nr" )
@@ -138,7 +168,8 @@ parse_config_file() {
138 168
 filter_all_songs() {
139 169
   local choice
140 170
   mapfile -t choice < <(mpc search -f "%file%\t$track_format" filename '' |
141
-    fzf --multi \
171
+    fzf --prompt='songs > ' \
172
+      --multi \
142 173
       --with-nth='2..' \
143 174
       --delimiter='\t' \
144 175
       --expect='f1,f2,f3,f4,enter' |
@@ -155,7 +186,7 @@ filter_all_songs() {
155 186
 filter_by_genre() {
156 187
   local choice
157 188
   mapfile -t choice < <(mpc search -f '%genre%' genre '' | awk 'NF' | sort | uniq -ic | sort -rn |
158
-    fzf \
189
+    fzf --prompt='genres > ' \
159 190
       --preview='mpc search -f "%artist%" genre {2..} | sort -u' \
160 191
       --bind="$findadd_key:execute:mpc findadd genre {2..}" \
161 192
       --expect='f1,f2,f3,f4,enter' | sed -r 's/^\s*[0-9]+\s*//')
@@ -175,8 +206,8 @@ filter_by_artist_from_genre() {
175 206
   genre="$1"
176 207
   mapfile -t choice < <(mpc search -f '%artist%' genre "$genre" | sort -u |
177 208
     awk 'NF' | sort -u |
178
-    fzf \
179
-      --preview="mpc search -f '%album%\t%title%' artist {} | awk -F'\t' '{ if(album != \$1) { album=\$1; print album } printf \"  %s\n\", \$2 }'" \
209
+    fzf --prompt="$genre > " \
210
+      --preview="$album_listing" \
180 211
       --expect='f1,f2,f3,f4,enter' \
181 212
       --bind="$findadd_key:execute:mpc findadd artist {}")
182 213
   (( ${#choice[@]} > 0 )) || filter_by_genre
@@ -193,8 +224,8 @@ filter_by_artist_from_genre() {
193 224
 filter_by_artist() {
194 225
   local choice
195 226
   mapfile -t choice < <(mpc list artist |
196
-    fzf \
197
-      --preview="mpc search -f '%album%\t%title%' artist {} | awk -F'\t' '{ if(album != \$1) { album=\$1; print album } printf \"  %s\n\", \$2 }'" \
227
+    fzf --prompt='artists > ' \
228
+      --preview="$album_listing" \
198 229
       --bind="$findadd_key:execute:mpc findadd artist {}" \
199 230
       --expect='f1,f2,f3,f4,enter')
200 231
   (( ${#choice[@]} > 0 )) || die
@@ -296,6 +327,7 @@ while :; do
296 327
     -A|--all) default_filter='filter_all_songs'; shift ;;
297 328
     -a|--artist) default_filter='filter_by_artist'; shift ;;
298 329
     -p|--playlist) default_filter='filter_by_playlist'; shift ;;
330
+    -g|--genre) default_filter='filter_by_genre'; shift ;;
299 331
     -h|--help) usage; exit ;;
300 332
     *) break
301 333
   esac

Loading…
Cancel
Save