From f045d9b1433170a95f2c97a67c12d683d825050c Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 13 Dec 2015 20:36:57 +0100 Subject: [PATCH] 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. --- share/completions/mount.fish | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/share/completions/mount.fish b/share/completions/mount.fish index fca4b791f..cb945f8d5 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'