diff options
author | Igor Murzov <e-mail@date.by> | 2011-12-04 05:34:25 +0400 |
---|---|---|
committer | Igor Murzov <e-mail@date.by> | 2011-12-04 05:34:25 +0400 |
commit | 54bcdff3cf7e7e40f7ae0f4f20b53287653aa233 (patch) | |
tree | 29110610f41c2e18267afcfc5dfa0cf330528696 | |
parent | 7a1a3da08a77de2952b75dc514fa962d874c5c95 (diff) | |
download | bash-completion-54bcdff3cf7e7e40f7ae0f4f20b53287653aa233.tar.gz |
umount: Real fix for completion of relative paths.
-rw-r--r-- | completions/umount.linux | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/completions/umount.linux b/completions/umount.linux index 3fbd544d..97231807 100644 --- a/completions/umount.linux +++ b/completions/umount.linux @@ -65,16 +65,27 @@ _linux_fstab() fi done - # Add some relative paths to COMPREPLY + # Add relative paths to COMPREPLY if [[ $cur && $cur != /* ]]; then - local i n=${#COMPREPLY[@]} - for (( i=0; i < $n; i++ )); do - if [[ "${COMPREPLY[i]}" == "$PWD"* ]]; then - [[ $cur == ./* ]] && - COMPREPLY+=( "./${COMPREPLY[i]##$PWD*(/)}" ) || - COMPREPLY+=( "${COMPREPLY[i]##$PWD*(/)}" ) + local realcur + [[ $cur == */ ]] && # don't let readlink drop last / from path + realcur="$( readlink -f "$cur." 2> /dev/null )/" || + realcur=$( readlink -f "$cur" 2> /dev/null ) + if [[ $realcur ]]; then + local dirrealcur= dircur= basecur + if [[ $cur == */* ]]; then + dirrealcur="${realcur%/*}/" + dircur="${cur%/*}/" fi - done + basecur=${cur#"$dircur"} + local i n=${#COMPREPLY[@]} + for (( i=0; i < $n; i++ )); do + [[ "${COMPREPLY[i]}" == "$realcur"* ]] && + COMPREPLY+=( $( cd "$dircur" 2> /dev/null && + compgen -f -d -P "$dircur" \ + -X "!${COMPREPLY[i]##"$dirrealcur"}" -- "$basecur" ) ) + done + fi fi _reply_compgen_array |