| 1 |
_umount_points_list() |
| 2 |
{ |
| 3 |
# List of characters to escape shamelessly stolen from "scp" completion |
| 4 |
local escape_chars='[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]' |
| 5 |
|
| 6 |
command findmnt -lno TARGET | command awk ' |
| 7 |
|
| 8 |
function literal_ere(s) { |
| 9 |
gsub(/[][^$.*?+{}\\()|]/, "\\\\&", s) |
| 10 |
return s |
| 11 |
} |
| 12 |
|
| 13 |
{ |
| 14 |
home_ere = literal_ere(ENVIRON["HOME"]) |
| 15 |
print home_ere |
| 16 |
if ($0 ~ "^"home_ere) { |
| 17 |
homeless = $0 |
| 18 |
sub("^"home_ere, "~", homeless) |
| 19 |
gsub("'"$escape_chars"'", "\\\\&", homeless) |
| 20 |
print homeless " " |
| 21 |
} |
| 22 |
pwd_ere = literal_ere(ENVIRON["PWD"]) |
| 23 |
if ($0 ~ "^"pwd_ere) { |
| 24 |
reldir = $0 |
| 25 |
sub("^"pwd_ere"/?", "", reldir) |
| 26 |
gsub("'"$escape_chars"'", "\\\\&", reldir) |
| 27 |
print "./" reldir " " |
| 28 |
print reldir " " |
| 29 |
} |
| 30 |
gsub("'"$escape_chars"'", "\\\\&") |
| 31 |
print $0 " " |
| 32 |
}' |
| 33 |
} |
| 34 |
|
| 35 |
_umount_module() |
| 36 |
{ |
| 37 |
local cur prev OPTS |
| 38 |
COMPREPLY=() |
| 39 |
cur="${COMP_WORDS[COMP_CWORD]}" |
| 40 |
prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 41 |
case $prev in |
| 42 |
'-t'|'--types') |
| 43 |
local TYPES |
| 44 |
TYPES=" |
| 45 |
$(command ls /lib/modules/$(command uname -r)/kernel/fs | command awk '{print $1, "no" $1}') |
| 46 |
$(command awk '{print $NF, "no" $NF}' /proc/filesystems) |
| 47 |
" |
| 48 |
COMPREPLY=( $(compgen -W "$TYPES" -- $cur) ) |
| 49 |
return 0 |
| 50 |
;; |
| 51 |
'-h'|'--help'|'-V'|'--version') |
| 52 |
return 0 |
| 53 |
;; |
| 54 |
'-N'|'--namespace') |
| 55 |
local NAMESPACE |
| 56 |
NAMESPACE="$(command lsns --type mnt --output PATH --noheadings)" |
| 57 |
COMPREPLY=( $(compgen -W "$NAMESPACE" -- $cur) ) |
| 58 |
return 0 |
| 59 |
;; |
| 60 |
esac |
| 61 |
case $cur in |
| 62 |
-*) |
| 63 |
OPTS=" --all |
| 64 |
--all-targets |
| 65 |
--no-canonicalize |
| 66 |
--detach-loop |
| 67 |
--fake |
| 68 |
--force |
| 69 |
--internal-only |
| 70 |
--namespace |
| 71 |
--no-mtab |
| 72 |
--lazy |
| 73 |
--test-opts |
| 74 |
--recursive |
| 75 |
--read-only |
| 76 |
--types |
| 77 |
--quiet |
| 78 |
--verbose |
| 79 |
--help |
| 80 |
--version" |
| 81 |
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) |
| 82 |
return 0 |
| 83 |
;; |
| 84 |
esac |
| 85 |
|
| 86 |
if command grep -q "^$cur" <(findmnt -lno TARGET); then |
| 87 |
local IFS=$'\n' |
| 88 |
COMPREPLY=( $( compgen -W '$( _umount_points_list )' -- "$cur" ) ) |
| 89 |
else |
| 90 |
compopt -o filenames |
| 91 |
COMPREPLY=( $(compgen -o dirnames -- "$cur") ) |
| 92 |
return 0 |
| 93 |
fi |
| 94 |
} |
| 95 |
complete -F _umount_module -o nospace umount |