Skip to content

Commit ce5cd71

Browse files
committed
mus: Add ability to select by position
1 parent 72b59b6 commit ce5cd71

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

mus

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ _mus_find() {
3838
(( ! $#fs )) && fs=(${(@f)"$(_ffind "$dir"/ -${cs-i}path "*$1*")"})
3939

4040
while (( $#fs > 1 )) && [[ ! -v list ]]; do
41-
for f in $fs; do >&2 echo ${f#"$dir"/}; done
41+
local i=1
42+
for f in $fs; do
43+
>&2 echo $i. ${f#"$dir"/}
44+
i=$((i + 1))
45+
done
4246

4347
>&2 echo
4448
>&2 read REPLY?"Which one? "
@@ -48,7 +52,13 @@ _mus_find() {
4852
case "$REPLY" in
4953
all|) break ;;
5054
q) return ;;
51-
*) fs=(${(M)fs:#*(#l)$REPLY*}) ;;
55+
*) # The pattern <-> is zsh-ism which matches any string
56+
# having any number of digits and only digits.
57+
if [[ "$REPLY" = <-> ]]; then
58+
fs=("${fs[$REPLY]}")
59+
else
60+
fs=(${(M)fs:#*(#l)$REPLY*})
61+
fi ;;
5262
esac
5363
done
5464

0 commit comments

Comments
 (0)