aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/completions
diff options
context:
space:
mode:
authorGravatar Fabian Homborg <FHomborg@gmail.com>2015-12-13 20:36:57 +0100
committerGravatar Fabian Homborg <FHomborg@gmail.com>2015-12-13 20:38:38 +0100
commitf045d9b1433170a95f2c97a67c12d683d825050c (patch)
tree3497372a0068bb6abc09668b84a900cd0a966227 /share/completions
parent6c8518dd1099cfec72f9a6861d2cc3cb831d479b (diff)
Improve mount completion (now with blockdevices!)
This adds blockdevices (and directories) and fixes the regexes to no longer include comments but include UUID= and LABEL=, which at least util-linux mount understands. It also shouldn't fail on systems without fstab any longer (like default OSX). Fixes #2606.
Diffstat (limited to 'share/completions')
-rw-r--r--share/completions/mount.fish22
1 files changed, 16 insertions, 6 deletions
diff --git a/share/completions/mount.fish b/share/completions/mount.fish
index fca4b791..cb945f8d 100644
--- a/share/completions/mount.fish
+++ b/share/completions/mount.fish
@@ -1,10 +1,20 @@
-
-
-# A list of all known filesystem types, used by various completions,
-# including mount and df
-
# Completions for mount
-complete -x -c mount -a '(cat /etc/fstab|sed -e "s/^\([^ \t]*\)[ \t]*\([^ \t]*\).*/\1\n\2/"| __fish_sgrep "^/")' --description 'Mount point'
+function __fish_complete_blockdevice
+ set -l cmd (commandline -ct)
+ [ "" = "$cmd" ]; and return
+ for f in $cmd*
+ [ -b $f ]; and printf "%s\t%s\n" $f "Block device"
+ [ -d $f ]; and printf "%s\n" $f/
+ end
+end
+
+complete -x -c mount -a '(__fish_complete_blockdevice)'
+# In case `mount UUID=` and similar also works
+complete -x -c mount -a "(test -r /etc/fstab; and string replace -r '#.*' '' < /etc/fstab | string match -r '.+' | string replace -r ' ([^\s]*) .*' '\tMount point \$1')"
+complete -x -c mount -a "(test -r /etc/fstab; and string replace -r '#.*' '' < /etc/fstab | string match -r '.+' | string replace -r '(^[^\s]*) ([^\s]*) .*' '\$2\tDevice \$1')"
+# In case it doesn't
+# complete -x -c mount -a "(test -r /etc/fstab; and string match -r '^/.*' < /etc/fstab | string replace -r ' ([^\s]*) .*' '\tMount point \$1')"
+# complete -x -c mount -a "(test -r /etc/fstab; and string match -r '^/.*' < /etc/fstab | string replace -r '(^/[^\s]*) ([^\s]*) .*' '\$2\tDevice \$1')"
complete -c mount -s V --description 'Display version and exit'
complete -c mount -s h --description 'Display help and exit'
complete -c mount -s v --description 'Verbose mode'