Re: [gentoo-user] Re: zsh: not so bad?

2015-07-14 Thread Emanuele Rusconi
On 14 July 2015 at 09:50, Alon Bar-Lev  wrote:
> On 14 July 2015 at 10:47, Emanuele Rusconi  wrote:
>> In my setup (borrowed from grml, which has an AWESOME zsh setup), ^xf
>> (ctrl-x f) is bound to "insert-files" and completes file names,
>> regardless of other completion rules
>> for the command I'm typing.
>>
>> -- Emanuele Rusconi
>>
>
> Great! will check it out.
> Command please? (for these that are new for zsh).

The grml's setup uses a custom function "bind2maps":

bind2maps emacs viins   -- -s "^xf" insert-files

I think the regular commands would be like:

bindkey -M emacs -s "^xf" insert-files
bindkey -M viins -s "^xf" insert-files



[gentoo-user] Re: zsh: not so bad?

2015-07-14 Thread Martin Vaeth
Alon Bar-Lev  wrote:
>
> I do not want to write completion for every command out there.

For most commands there already do exist completion functions.
Essentially, it is only your own scripts for which you have
to do it, and this does not take a lot of time when you write
the scripts anyway...
In my case, I had to write 11 files (not counting
the projects which I had made public for which I wrote
completions files, of course, as well).
It is a surprisingly low number of commands which one really
uses, and the time spent to write a completion was always
worth it, in the end...

> I did not press tab and it completes...

This can happen only if you are using something like auto-fu-zsh.
The latter is very convenient, but only if you have
"perfect" completion functions for everything.
Otherwise it can be very annoying.

>> Usually there is no point to specify this globally.
>
> yes there is, most commands that have no specific completion will
> enjoy --xxx= to complete a file name.

Don't do it (trying to enable "correct" completion for
commands without completion files) - it will fail anyway:
There is no "generic" completion which is always right.

You might try to write some "generic" completion functions
and assign them to a whole bulk of your commands, but in my
experience you are bettter off to spend the time to write
correct completions in the first place.

> how? can you give an example?

/usr/share/zsh/site-functions/_enjoy:

#compdef enjoy
_arguments : \
'--file=[use specified file for output]:output file:_files' \
'*:files:_files'




Re: [gentoo-user] Re: zsh: not so bad?

2015-07-14 Thread Alon Bar-Lev
On 14 July 2015 at 10:47, Emanuele Rusconi  wrote:
> In my setup (borrowed from grml, which has an AWESOME zsh setup), ^xf
> (ctrl-x f) is bound to "insert-files" and completes file names,
> regardless of other completion rules
> for the command I'm typing.
>
> -- Emanuele Rusconi
>

Great! will check it out.
Command please? (for these that are new for zsh).



Re: [gentoo-user] Re: zsh: not so bad?

2015-07-14 Thread Emanuele Rusconi
In my setup (borrowed from grml, which has an AWESOME zsh setup), ^xf
(ctrl-x f) is bound to "insert-files" and completes file names,
regardless of other completion rules
for the command I'm typing.

-- Emanuele Rusconi



Re: [gentoo-user] Re: zsh: not so bad?

2015-07-13 Thread Alon Bar-Lev
On 14 July 2015 at 08:42, Martin Vaeth  wrote:
> Alon Bar-Lev  wrote:
>>
>> Only issue I could not find a solution to is tab completion after '=',
>> for example:
>>
>> xxx --file=
>>
>> This will not complete files, while it will be nice if it does.
>
> For standard commands, it works as it should. For instance,
>
> tar --file=
> chmod --reference=
> dd if=
>
> all work as excpected. For your own custom-commands, it is usually the
> best idea to write your own _custom-command completion file for _zsh
> where you can specify the options and their arguments (and how the
> option arguments can look like, e.g. whether "=" is acceptable
> as an option-argument separator) in detail.
>
> For instance, gentoo-zsh-completion does this for most commands of
> gentoo projects, others like eix bring their own completion files.
> If you don't, you do not get completion for options but only the
> "generic" completion of filenames (in which case "=" has no magic
> meaning, of course).

I do not want to write completion for every command out there.

>
>> There is magic_equal_subst option which enables that but also cause
>> harm when using = in other places such as:
>
> That's exactly the purpose of magic_equal_subst:
> To support it for *all* arguments everywhere.

no, it also has side unwanted side effects that have nothing to do
with completion. I gave the example of:

echo xxx==cat

I did not press tab and it completes...

> Usually there is no point to specify this globally.

yes there is, most commands that have no specific completion will
enjoy --xxx= to complete a file name.

> You can of course set it locally in a specific completion function,
> in which you want it (although other completion helper functions
> like _arguments are usually sufficient to treat "=" correctly).

how? can you give an example?

>> Is there any sequence to enable completion after space without
>> effecting the entire interpreter?
>
> After "space"? I suppose the question you meant is answered above.

I was confused, after '=', and I am afraid I do not have an answer.

Thanks for your answer!
Alon



[gentoo-user] Re: zsh: not so bad?

2015-07-13 Thread Martin Vaeth
Alon Bar-Lev  wrote:
>
> Only issue I could not find a solution to is tab completion after '=',
> for example:
>
> xxx --file=
>
> This will not complete files, while it will be nice if it does.

For standard commands, it works as it should. For instance,

tar --file=
chmod --reference=
dd if=

all work as excpected. For your own custom-commands, it is usually the
best idea to write your own _custom-command completion file for _zsh
where you can specify the options and their arguments (and how the
option arguments can look like, e.g. whether "=" is acceptable
as an option-argument separator) in detail.

For instance, gentoo-zsh-completion does this for most commands of
gentoo projects, others like eix bring their own completion files.
If you don't, you do not get completion for options but only the
"generic" completion of filenames (in which case "=" has no magic
meaning, of course).

> There is magic_equal_subst option which enables that but also cause
> harm when using = in other places such as:

That's exactly the purpose of magic_equal_subst:
To support it for *all* arguments everywhere.
Usually there is no point to specify this globally.
You can of course set it locally in a specific completion function,
in which you want it (although other completion helper functions
like _arguments are usually sufficient to treat "=" correctly).

> Is there any sequence to enable completion after space without
> effecting the entire interpreter?

After "space"? I suppose the question you meant is answered above.




[gentoo-user] Re: zsh: not so bad?

2015-07-12 Thread Martin Vaeth
Andrew Tselischev  wrote:
> On Sun, Jul 12, 2015 at 06:52:35PM -0700, walt wrote:
[...]
>> http://wiki.redbrick.dcu.ie/mw/Account_Customisation_(zsh)

Note that this does not activate all features e.g. concerning
completion: You can have files displayed in your custom "ls"
colors in the "selection" list, you can have explanations about
the argument you are about to complete, you can have explanations
about the completing options being displayed in the list, etc.

I once more advertise zshrc-mv ...

Note that this sets the prompt only if you also install "set_prompt".

Also zsh-syntax-highlighting and auto-fu-zsh are supported
by zshrc-mv only if the packages are installed, of course:
I really like these features: One displays you commands, options,
strings, files, etc in different colors while typing, the other
"auto-completes" names for you while typing.
(Note that for combining both, you must install the development
versioen of auto-fu-zsh, since its author apparently does not
want to release non-git versions anymore.)

>> I made the change to PS1 permanent

set_prompt from the mv overlay can produce a prompt
for bash as well as for zsh.

In general, the zsh features for PS1 are also more powerful
than those of bash, e.g. it can automatically cut too long
texts. (Although set_prompt does not make use of these features,
becaues currently zsh does not autoamtically change colors in this
case which I wanted to have.)

However, be aware that some PS1 suggestions in the wild
(e.g. from the earlier mentioned oh-my-zsh) can turn out to be
a security risk. For instance, many custom prompts display
information about the git repository (if you are in some)
in an insecure way: I would noot rely that git cannot be
subject to some buffer overflow if e.g. you enter as root
a directory where some malicious user prepared a handcrafted .git ...

> zsh can also auto-complete all sorts of things, including process list
> for `kill' and `pkill', zfs datasets for the zfs and zpool commands...
> you can even write your own completions for any command.

Both is, in principle, also supported by bash, but usually the
zsh completion is better. Moreover, in contrast to bash completion,
it is easily customizable. For instance in the above mentioned
completion list for processes, you can have different colors
in the display for process numbers, tty, time, and name...
You can also select to have certain types being completed differently.
This is important if e.g. you prefer that "restricting" commands
like e.g. "mplayer ..." should not only provide the "typical" extensions
which mplayer is capable to display but really all files...

I write all this, because most of these things you do not know, still,
when you read the zsh manpage...