* Alter completion for mv
@ 2014-10-02 13:27 Daniel
2014-10-02 21:20 ` zzapper
2014-10-03 2:09 ` Bart Schaefer
0 siblings, 2 replies; 3+ messages in thread
From: Daniel @ 2014-10-02 13:27 UTC (permalink / raw)
To: zsh-users
I would like completion of the destination argument for mv(1) to first
complete directories. Is this possible by toggling an option, or could
somebody help me out?
The idea is that I most often do this task -- move something to somewhere --
rather than overwriting a file. (In the latter case, perhaps if "-f" is given,
completion should always prefer files).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Alter completion for mv
2014-10-02 13:27 Alter completion for mv Daniel
@ 2014-10-02 21:20 ` zzapper
2014-10-03 2:09 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: zzapper @ 2014-10-02 21:20 UTC (permalink / raw)
To: zsh-users
Daniel <quite@hack.org> wrote in news:m0jjrn$hrl$1@ger.gmane.org:
?
>
> The idea is that I most often do this task -- move something to
> somewhere -- rather than overwriting a file. (In the latter case,
> perhaps if "-f" is given, completion should always prefer files).
>
>
While not answering your actual question , a discipline I've learnt by
bitter experience is to always add the trailing slash
mv fred.jpg tmp/
--
zzapper
https://twitter.com/dailyzshtip
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Alter completion for mv
2014-10-02 13:27 Alter completion for mv Daniel
2014-10-02 21:20 ` zzapper
@ 2014-10-03 2:09 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2014-10-03 2:09 UTC (permalink / raw)
To: zsh-users
On Oct 2, 1:27pm, Daniel wrote:
}
} I would like completion of the destination argument for mv(1) to first
} complete directories. Is this possible by toggling an option, or could
} somebody help me out?
Start by telling completion that it should default to grouping matches
by tag:
zstyle ':completion:*' group-name ''
Check that you don't already have a conflicting zstyle for group-name.
Then, if mv is GNU mv (e.g. on linux), the best way is probably this:
compdef _gnu_generic mv
zstyle -e :completion::complete:mv:argument-rest: list-dirs-first \
'(( ! ${words[(I)--target-directory=*]} )) &&
compset -N "-*"; reply=( $((CURRENT > 1)) )'
Otherwise this will be mostly correct:
zstyle ':completion:*' group-name ''
zstyle -e :completion::complete:mv:: list-dirs-first \
'compset -N "-*"; reply=( $((CURRENT > 1)) )'
The "compset" in both examples discards options (-i, -v, etc.) that
might appear, so that you can tell which non-option word position you
are in. That also discards the command name itself, so you are left
with nothing but the non-option arguments, of which any after the
first one might be the destination argument.
There isn't a "list-files-first" style, but list-dirs-first splits
the completions into directories and other-files, so to get "prefer
files when -f is given" you can add
zstyle -e ':completion::complete:mv::' group-order \
'(( ${words[(I)(-f|--force)]} )) && \
reply=( other-files directories )'
Note you use ':completion::complete:mv::' for both the GNU and other
examples, otherwise this style is checked too late and compset will
have already removed the -f option from $words.
This overrides the default order (directories other-files) that the
list-dirs-first style would use. Improve the pattern in the $words
subscript if you want to also match -f when it is combined with some
other flag in the same word (-uf, maybe).
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-10-03 2:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-02 13:27 Alter completion for mv Daniel
2014-10-02 21:20 ` zzapper
2014-10-03 2:09 ` 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).