* wierd sshfs completion
@ 2009-03-21 11:03 Freak
2009-03-21 12:28 ` Daniel Friesel
0 siblings, 1 reply; 6+ messages in thread
From: Freak @ 2009-03-21 11:03 UTC (permalink / raw)
To: zsh-users
Hello guys,
(please use CC as I'm not subscribed)
I'm having problems with my sshfs completion. Some Information:
zsh 4.3.9 (x86_64-unknown-linux-gnu)
Distribution: Archlinux
I'm using the config from http://www.jukie.net/~bart/conf/
With some modifications:
hosts=($((
( [ -r ~/.ssh/config ] && awk '/^host +[a-z]/ { print $2 }'
~/.ssh/config) ;\
) | sort -u))
zstyle ':completion:*' hosts $hosts
zstyle ':completion:*' host $hosts
users=(<someusers>)
zstyle ':completion:*' users $users
The problem:
sshfs <tab>
---- remote directory
<users>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: wierd sshfs completion
2009-03-21 11:03 wierd sshfs completion Freak
@ 2009-03-21 12:28 ` Daniel Friesel
2009-03-21 12:31 ` Freak
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Friesel @ 2009-03-21 12:28 UTC (permalink / raw)
To: zsh-users; +Cc: freakguard
[-- Attachment #1: Type: text/plain, Size: 336 bytes --]
On Sat, Mar 21, 2009 at 12:03:20PM +0100, Freak wrote:
> The problem:
> sshfs <tab>
> ---- remote directory
> <users>
I think I had the same problem a while ago... but I can't exactly recall
the reason for it.
The attached completion file should fix at least the match description,
just put it into some directory in $fpath to use it.
[-- Attachment #2: _sshfs --]
[-- Type: text/plain, Size: 2442 bytes --]
#compdef sshfs
## Since _user_at_host was a little inflexible,
## I ripped the responsible parts from _ssh.
## In future, sshfs should be handled by _ssh as well
## Copyright goes to whoever wrote _ssh (if in doubt, the zsh dudes)
typeset expl lstate tmp
_arguments \
'-V[version]' \
'-p:tcp port:' \
'-C[compression]' \
'-o:options:_values -s , "sshfs or fuse or mount options" reconnect sshfs_sync no_readahead sshfs_debug cache=:cache\ setting:(yes no) cache_timeout=:seconds: cache_stat_timeout=:seconds: cache_dir_timeout=:seconds: cache_link_timeout=:seconds: ssh_command=:ssh\ command:_command_names directport=:port: SSHOPT=:ssh\ option: default_permissions allow_other allow_root kernel_cache large_read direct_io max_read=:size: hard_remove debug fs_name=:name: use_ino readdir_ino' \
'-d[debug]' \
'-f[foreground]' \
'-s[disable multithreaded operation]' \
'-r[mount read-only]' \
'-h[help]' \
':remote directory:->userhost' \
':mountpoint:_files -/'
_ssh_users () {
_combination -s '[:@]' my-accounts users-hosts users "$@"
}
_ssh_hosts () {
local -a config_hosts
local config
integer ind
# If users-hosts matches, we shouldn't complete anything else.
if [[ "$IPREFIX" == *@ ]]; then
_combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" && return
else
_combination -s '[:@]' my-accounts users-hosts \
${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@" && return
fi
if (( ind = ${words[(I)-F]} )); then
config=${~words[ind+1]}
else
config="$HOME/.ssh/config"
fi
if [[ -r $config ]]; then
local IFS=$'\t ' key hosts host
while read key hosts; do
if [[ "$key" == (#i)host ]]; then
for host in ${(z)hosts}; do
case $host in
(*[*?]*) ;;
(*) config_hosts+=("$host") ;;
esac
done
fi
done < "$config"
if (( ${#config_hosts} )); then
_wanted hosts expl 'remote host name' \
compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts
fi
fi
}
while [[ -n $state ]]; do
lstate=$state
state=''
case $lstate in
userhost)
if compset -P '*@'; then
_wanted hosts expl 'remote host name' _ssh_hosts
elif compset -S '@*'; then
_wanted users expl 'login name' _ssh_users -S ''
else
if (( $+opt_args[-l] )); then
tmp=()
else
tmp=( 'users:login name:_ssh_users -qS@' )
fi
_alternative \
'hosts:remote host name:_ssh_hosts' \
"$tmp[@]"
fi
;;
esac
done
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: wierd sshfs completion
2009-03-21 12:28 ` Daniel Friesel
@ 2009-03-21 12:31 ` Freak
2009-03-21 13:06 ` Daniel Friesel
0 siblings, 1 reply; 6+ messages in thread
From: Freak @ 2009-03-21 12:31 UTC (permalink / raw)
To: zsh-users
On Saturday 21 March 2009 13.28:41 you wrote:
> On Sat, Mar 21, 2009 at 12:03:20PM +0100, Freak wrote:
> > The problem:
> > sshfs <tab>
> > ---- remote directory
> > <users>
>
> I think I had the same problem a while ago... but I can't exactly recall
> the reason for it.
> The attached completion file should fix at least the match description,
> just put it into some directory in $fpath to use it.
Hm... works partially. First tab:
---- remote host name
<host names>
---- login name
<user names>
Works good. But after choosing a remote hostname <tab>:
(space)<local dirs>
It should display remote dirs instead (like scp)
Greetings
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: wierd sshfs completion
2009-03-21 12:31 ` Freak
@ 2009-03-21 13:06 ` Daniel Friesel
2009-03-21 13:05 ` Freak
2009-03-21 15:10 ` Bart Schaefer
0 siblings, 2 replies; 6+ messages in thread
From: Daniel Friesel @ 2009-03-21 13:06 UTC (permalink / raw)
To: zsh-users; +Cc: freakguard
[-- Attachment #1: Type: text/plain, Size: 459 bytes --]
On Sat, Mar 21, 2009 at 01:31:32PM +0100, Freak wrote:
> Works good. But after choosing a remote hostname <tab>:
> (space)<local dirs>
>
> It should display remote dirs instead (like scp)
There you go ;)
But this is a really ugly solution, this _sshfs almost entirely consists
of snippets from _ssh.
One should think about either splitting up _ssh so that for example
_remote_files can be used by other scripts as well, or adding sshfs
completion to _ssh.
[-- Attachment #2: _sshfs --]
[-- Type: text/plain, Size: 3608 bytes --]
#compdef sshfs
## Since _user_at_host was a little inflexible,
## I ripped the responsible parts from _ssh.
## In future, sshfs should be handled by _ssh as well
## Copyright goes to whoever wrote _ssh (if in doubt, the zsh dudes)
typeset expl lstate tmp
_remote_files () {
# There should be coloring based on all the different ls -F classifiers.
local expl rempat remfiles remdispf remdispd args suf ret=1
if zstyle -T ":completion:${curcontext}:files" remote-access; then
zparseopts -D -E -a args p: 1 2 4 6 F:
if [[ -z $QIPREFIX ]]
then rempat="${PREFIX%%[^./][^/]#}\*"
else rempat="${(q)PREFIX%%[^./][^/]#}\*"
fi
remfiles=(${(M)${(f)"$(_call_program files ssh -o BatchMode=yes $args -a -x ${IPREFIX%:} ls -d1FL "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
compset -P '*/'
compset -S '/*' || suf='remote file'
remdispf=(${remfiles:#*/})
remdispd=(${(M)remfiles:#*/})
_tags files
while _tags; do
while _next_label files expl ${suf:-remote directory}; do
[[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
${(q)remdispf%[*=@|]} && ret=0
compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
${(q)remdispd%/} && ret=0
done
(( ret )) || return 0
done
return ret
else
_message -e remote-files 'remote file'
fi
}
_arguments \
'-V[version]' \
'-p:tcp port:' \
'-C[compression]' \
'-o:options:_values -s , "sshfs or fuse or mount options" reconnect sshfs_sync no_readahead sshfs_debug cache=:cache\ setting:(yes no) cache_timeout=:seconds: cache_stat_timeout=:seconds: cache_dir_timeout=:seconds: cache_link_timeout=:seconds: ssh_command=:ssh\ command:_command_names directport=:port: SSHOPT=:ssh\ option: default_permissions allow_other allow_root kernel_cache large_read direct_io max_read=:size: hard_remove debug fs_name=:name: use_ino readdir_ino' \
'-d[debug]' \
'-f[foreground]' \
'-s[disable multithreaded operation]' \
'-r[mount read-only]' \
'-h[help]' \
':remote directory:->userhost' \
':mountpoint:_files -/'
_ssh_users () {
_combination -s '[:@]' my-accounts users-hosts users "$@"
}
_ssh_hosts () {
local -a config_hosts
local config
integer ind
# If users-hosts matches, we shouldn't complete anything else.
if [[ "$IPREFIX" == *@ ]]; then
_combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" && return
else
_combination -s '[:@]' my-accounts users-hosts \
${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@" && return
fi
if (( ind = ${words[(I)-F]} )); then
config=${~words[ind+1]}
else
config="$HOME/.ssh/config"
fi
if [[ -r $config ]]; then
local IFS=$'\t ' key hosts host
while read key hosts; do
if [[ "$key" == (#i)host ]]; then
for host in ${(z)hosts}; do
case $host in
(*[*?]*) ;;
(*) config_hosts+=("$host") ;;
esac
done
fi
done < "$config"
if (( ${#config_hosts} )); then
_wanted hosts expl 'remote host name' \
compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts
fi
fi
}
while [[ -n $state ]]; do
lstate=$state
state=''
case $lstate in
userhost)
if compset -P '*:'; then
_remote_files ${(kv)~opt_args[(I)-[FP1246]]/-P/-p} && ret=0
elif compset -P '*@'; then
_wanted hosts expl 'remote host name' _ssh_hosts -S ':'
elif compset -S '@*'; then
_wanted users expl 'login name' _ssh_users -S ''
else
if (( $+opt_args[-l] )); then
tmp=()
else
tmp=( 'users:login name:_ssh_users -qS@' )
fi
_alternative \
'hosts:remote host name:_ssh_hosts -S :' \
"$tmp[@]"
fi
;;
esac
done
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: wierd sshfs completion
2009-03-21 13:06 ` Daniel Friesel
@ 2009-03-21 13:05 ` Freak
2009-03-21 15:10 ` Bart Schaefer
1 sibling, 0 replies; 6+ messages in thread
From: Freak @ 2009-03-21 13:05 UTC (permalink / raw)
To: zsh-users
On Saturday 21 March 2009 14.06:23 you wrote:
> On Sat, Mar 21, 2009 at 01:31:32PM +0100, Freak wrote:
> > Works good. But after choosing a remote hostname <tab>:
> > (space)<local dirs>
> >
> > It should display remote dirs instead (like scp)
>
> There you go ;)
Works fine! Thanks :)
> But this is a really ugly solution, this _sshfs almost entirely consists
> of snippets from _ssh.
> One should think about either splitting up _ssh so that for example
> _remote_files can be used by other scripts as well, or adding sshfs
> completion to _ssh.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: wierd sshfs completion
2009-03-21 13:06 ` Daniel Friesel
2009-03-21 13:05 ` Freak
@ 2009-03-21 15:10 ` Bart Schaefer
1 sibling, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2009-03-21 15:10 UTC (permalink / raw)
To: Daniel Friesel, zsh-users; +Cc: freakguard
On Mar 21, 2:06pm, Daniel Friesel wrote:
}
} One should think about either splitting up _ssh so that for example
} _remote_files can be used by other scripts as well, or adding sshfs
} completion to _ssh.
Try
compdef sshfs=scp
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-03-21 15:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-21 11:03 wierd sshfs completion Freak
2009-03-21 12:28 ` Daniel Friesel
2009-03-21 12:31 ` Freak
2009-03-21 13:06 ` Daniel Friesel
2009-03-21 13:05 ` Freak
2009-03-21 15:10 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).