[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 894c8778273272c754e50e8fd097d27eb00fdff3

Ville Skyttä ville.skytta at iki.fi
Fri Dec 25 10:01:15 UTC 2009


The following commit has been merged in the master branch:
commit e0acaf8ed285da180d9320759a734b4ce9d5a7fb
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Thu Dec 24 16:18:27 2009 +0200

    Split sshfs from contrib/ssh to contrib/sshfs.

diff --git a/CHANGES b/CHANGES
index fa58644..f5224d1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -48,6 +48,7 @@ bash-completion (2.x)
   * Turn on -o filenames in _filedir on bash >= 4.
   * Deprecate modules completion, upstream modules >= 3.2.7 ships one.
   * Protect grep invocations from user aliases (Alioth: 312143).
+  * Split sshfs completion from contrib/ssh into contrib/sshfs.
 
   [ Freddy Vulto ]
   * Added _get_pword() helper function, thanks to Sung Pae (Alioth: #312030)
diff --git a/Makefile.am b/Makefile.am
index 9f2cb5b..af557c0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -123,6 +123,7 @@ bashcomp_DATA = contrib/abook \
 		contrib/smartctl \
 		contrib/snownews \
 		contrib/ssh \
+		contrib/sshfs \
 		contrib/strace \
 		contrib/svk \
 		contrib/sysctl \
diff --git a/contrib/ssh b/contrib/ssh
index 650d960..ca11b71 100644
--- a/contrib/ssh
+++ b/contrib/ssh
@@ -299,6 +299,7 @@ _scp()
 
         [[ "$cur" == */* ]] || _known_hosts_real -c -a -F "$configfile" "$cur"
     fi
+
     # This approach is used instead of _filedir to get a space appended
     # after local file/dir completions, and -o nospace retained for others.
     local IFS=$'\t\n'
@@ -308,7 +309,7 @@ _scp()
 
     return 0
 }
-complete -F _scp -o nospace scp sshfs
+complete -F _scp -o nospace scp
 
 # ssh-copy-id(1) completion
 #
diff --git a/contrib/sshfs b/contrib/sshfs
new file mode 100644
index 0000000..9301b63
--- /dev/null
+++ b/contrib/sshfs
@@ -0,0 +1,54 @@
+# sshfs(1) completion
+
+have sshfs && have ssh &&
+_sshfs()
+{
+    local cur userhost path
+
+    COMPREPLY=()
+    cur=`_get_cword ":"`
+
+    _expand || return 0
+
+    # things we want to backslash escape
+    local esc="[][(){}<>\",:;^&\!$=?\`|\\ ']"
+
+    if [[ "$cur" == *:* ]]; then
+        local IFS=$'\t\n'
+        # remove backslash escape from the first colon
+        cur=${cur/\\:/:}
+        userhost=${cur%%?(\\):*}
+        path=${cur#*:}
+        # unescape (3 backslashes to 1 for chars we escaped)
+        path=$( sed -e 's/\\\\\\\('$esc'\)/\\\1/g' <<<"$path" )
+        if [ -z "$path" ]; then
+            # default to home dir of specified user on remote host
+            path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
+        fi
+        # escape spaces; remove executables, aliases, pipes and sockets;
+        # add space at end of file names
+        COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
+            command ls -aF1d "$path*" 2>/dev/null | \
+            sed -e 's/'$esc'/\\\\\\&/g' -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
+        return 0
+    fi
+
+    [[ "$cur" == */* ]] || _known_hosts_real -c -a "$cur"
+
+    # This approach is used instead of _filedir to get a space appended
+    # after local file/dir completions, and -o nospace retained for others.
+    local IFS=$'\t\n'
+    COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* 2>/dev/null | \
+        sed -e "s/$esc/\\\\&/g" -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
+
+    return 0
+} &&
+complete -F _sshfs -o nospace sshfs
+
+# Local variables:
+# mode: shell-script
+# sh-basic-offset: 4
+# sh-indent-comment: t
+# indent-tabs-mode: nil
+# End:
+# ex: ts=4 sw=4 et filetype=sh

-- 
bash-completion



More information about the Bash-completion-commits mailing list