Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ZSH users (lovers?) thread
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3 ... , 11, 12, 13  Next  
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Tue Aug 14, 2012 6:11 pm    Post subject: Reply with quote

khayyam wrote:
provide the bug #

Here is the bug. Let us wait what the maintainers will decide. If they reject it, the support might be continued in some overlay (by mv or somebody else): After all, it should not be so hard to apply a patch to an ebuild...
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Aug 16, 2012 7:39 am    Post subject: Reply with quote

mv wrote:
Here is the bug. Let us wait what the maintainers will decide. If they reject it, the support might be continued in some overlay (by mv or somebody else): After all, it should not be so hard to apply a patch to an ebuild...

mv ... ok, I voted. I think perhaps the only issue the devs might have is the extra dependency for USE="run-help", but I think overall it'd be an improvement so hopefully it'll be rolled in.

best ... khay
Back to top
View user's profile Send private message
kiksen
Guru
Guru


Joined: 24 Jun 2002
Posts: 401
Location: Denmark

PostPosted: Sat Aug 18, 2012 4:56 pm    Post subject: A very fine starting point for .zshrc Reply with quote

Hi, I'm a little late to the party in this thread, but I've had much pleasure in using the .zshrc from http://grml.org/zsh/
Many co-workers shift to zsh when we've worked at my terminal for a while (both Linux and OSX users)

Try it if you dare :)
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Aug 18, 2012 6:00 pm    Post subject: Re: A very fine starting point for .zshrc Reply with quote

kiksen wrote:
[...] I've had much pleasure in using the .zshrc from http://grml.org/zsh/ [...] Try it if you dare

kiksen ... I've read their config some time back and wasn't impressed. I want my .zshrc to be parsed quickly and all of those functions, tests, hashes, aliases, etc, are going to have the accumulative effect of slowing this down. I know enough about how to configure the shell, the version and its capabilities, the tools available, etc, etc, that using something like grml would be to use a hammer to fasten a safety pin.

best ... khay
Back to top
View user's profile Send private message
kiksen
Guru
Guru


Joined: 24 Jun 2002
Posts: 401
Location: Denmark

PostPosted: Sat Aug 18, 2012 7:38 pm    Post subject: Reply with quote

khayyam: Sure, if you know how or are willing to spent some time, nothing beats your own config. But a lot of people I meet wants/needs something that works right away. For that, I think grml's config makes a great starting point.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Aug 18, 2012 9:58 pm    Post subject: Reply with quote

kiksen wrote:
khayyam: Sure, if you know how or are willing to spent some time, nothing beats your own config. But a lot of people I meet wants/needs something that works right away. For that, I think grml's config makes a great starting point.

kiksen ... and this is part of the problem. How can one judge if it "works" if one has no idea how it works? The default zsh setup "works" for all intent and purpose, but it allows the user to customise it to suit their particular needs, now, if the user has no idea of what their particular needs are and adopts a pre-made 'solution' (sic) then there is no decision/reflection involved, and so no aquistion of skill, understanding, etc. Its simply adopting something on the basis of a pretty prompt, or what-have-you. Now, this is no more than adoption, not configuration, and before you know it its a dependency ... and this the is path to questions like: where the hell is the 'Start' button.

As the saying goes, its better to be at the bottom of a ladder that you want to climb than to be half way up a ladder you don't.

best ... khay
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Sun Jan 06, 2013 8:42 pm    Post subject: Reply with quote

If you want to activate a bulk of features of zsh (which is not the case by default), you can now have a look what zsh really can by installing zshrc-mv from the mv overlay (available via layman) and then also installing the packages recommended during installing.
Perhaps even experienced users might want to have a look.

Let me know if you think that I missed a convenient feature (things like spelling correction completion or the "!" history handling, I do not consider convenient) or if you have other comments.
Back to top
View user's profile Send private message
_______0
Guru
Guru


Joined: 15 Oct 2012
Posts: 521

PostPosted: Mon Jan 07, 2013 4:38 pm    Post subject: Reply with quote

hi,

how to manual configure missing command completion? Are there templates where one can simply change the command and fill in the new options??

thnks
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Mon Jan 07, 2013 5:49 pm    Post subject: Reply with quote

_______0 wrote:
how to manual configure missing command completion? Are there templates where one can simply change the command and fill in the new options??

Since there are commands with very complex arguments, this can be very complicated. If possible you should ask upstream to provide a zsh completion file for a command which is missing support (although most commands do have completion... some are only installed if you have USE=zsh-completion in your make.conf, and you should also emerge zsh-completion for support of most portage commands). For your own scripts you might copy some of the simpler files from /usr/share/zsh/site-functions/ or /usr/share/zsh/*/functions/Completion/* as a basis: For simple scripts, usually a call to the _arguments function with appropriate arguments is sufficient, see e.g. /usr/share/zsh/*/functions/Completion/X/_gqview. However, I admit that it is rather complicated to understand all the details: "man zshcompsys" describes _arguments, but for more complex completions, the information on that manpage is by far not sufficient.
Back to top
View user's profile Send private message
_______0
Guru
Guru


Joined: 15 Oct 2012
Posts: 521

PostPosted: Tue Jan 08, 2013 1:37 pm    Post subject: Reply with quote

mv wrote:
Since there are commands with very complex arguments ...


fine, but then I won't start with highly theoretical and abstract commands, but with something simple like aplaymidi.

Is it possible then?
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Tue Jan 08, 2013 9:03 pm    Post subject: Reply with quote

_______0 wrote:
something simple like aplaymidi.

Depends on how intelligent you want to make the completion for the -p option. If you want no completion there, using the mentioned _gqview as a basis (and reading the _argument description in the mentioned manpage [or looking up other examples] to treat the argument for the -d and -p option properly) would do.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Wed Jan 09, 2013 8:51 am    Post subject: Reply with quote

If the command has a decent help, then a simple completion can be often obtained by using _gnu_generic.
Code:
compdef _gnu_generic <command name>
For example enlightenment_remote's help looks like this:
Code:
~/tmp» enlightenment_remote -h

OPTIONS:
  -h This help
  -help This help
  --help This help
  --h This help
  --help-new Info about this tool
...
And the completion looks like this
Code:
~/tmp» compdef _gnu_generic enlightenment_remote
~/tmp» enlightenment_remote -
- option -
-default-profile-get                   -- Get the default configuration profile                             
-default-profile-set                   -- OPT1 Set the default configuration profile to OPT1               
-desktop-bg-add                        -- OPT1 OPT2 OPT3 OPT4 OPT5 Add a desktop bg definition. OPT1 = conta
-desktop-bg-del                        -- OPT1 OPT2 OPT3 OPT4 Delete a desktop bg definition. OPT1 = contain
-desktop-bg-list                       -- List all current desktop bg definitions
....

_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
_______0
Guru
Guru


Joined: 15 Oct 2012
Posts: 521

PostPosted: Wed Jan 09, 2013 11:41 am    Post subject: Reply with quote

ppurka wrote:
If the command has a decent help, then a simple completion can be often obtained by using _gnu_generic.
Code:
compdef _gnu_generic <command name>


wow, very smart!! the command parses the man pages to avoid hand writing the completion!! That's pretty useful for options completion. But as mv stated it gets complicated the completion for the options themselves since they fall outside the man pages and compdef _gnu_generic doesn't have psychic powers to know what the options are looking for.

thanks a lot I will try compdef _gnu_generic.

Where are the files telling zsh what it's to be completed and what not? Or compdef _gnu_generic parses man pages on the fly?

ps: just tried it, compdef _gnu_generic works as advertised.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Wed Jan 09, 2013 12:22 pm    Post subject: Reply with quote

_______0 wrote:
Where are the files telling zsh what it's to be completed and what not? Or compdef _gnu_generic parses man pages on the fly?

ps: just tried it, compdef _gnu_generic works as advertised.
It doesn't parse the manpage. It just parses the output of "command --help".
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
_______0
Guru
Guru


Joined: 15 Oct 2012
Posts: 521

PostPosted: Fri Jan 11, 2013 10:56 am    Post subject: Reply with quote

how to turn on tab completion with systemrescuecd's behaviour? Tab then get a colored list of files that's navigable with arrows?

thnks
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sun Jan 13, 2013 3:18 pm    Post subject: Reply with quote

_______0 wrote:
how to turn on tab completion with systemrescuecd's behaviour? Tab then get a colored list of files that's navigable with arrows?

thnks
Code:
# Colors in tab completion
zstyle ':completion:*:default'          list-colors \
    'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==34=00}:${(s.:.)ZLS_COLORS}")'

There are some nice zshrc files on the web. There is zsh wiki. There is oh-my-zsh https://github.com/robbyrussell/oh-my-zsh with lots and lots of forks! :)
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Sun Jan 13, 2013 5:42 pm    Post subject: Reply with quote

ppurka wrote:
There is oh-my-zsh with lots and lots of forks! :)

This is also available from the mv overlay, but I would recommend instead the zshrc-mv from there. IMHO, oh-my-zsh does a lot of things in a wrong way:
It is not necessarily useful to have a full prompt line which displays lots of details just because you can - soon, you will not look at it at all and the provided value in daily use is nothing. It is better to focus on what really helps (which IMHO is done in zshrc-mv, although perhaps auto-fu-zsh is already arguable).
However, this was discussed here earlier.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sun Jan 13, 2013 6:48 pm    Post subject: Reply with quote

mv wrote:
ppurka wrote:
There is oh-my-zsh with lots and lots of forks! :)

This is also available from the mv overlay, but I would recommend instead the zshrc-mv from there. IMHO, oh-my-zsh does a lot of things in a wrong way:
It is not necessarily useful to have a full prompt line which displays lots of details just because you can - soon, you will not look at it at all and the provided value in daily use is nothing. It is better to focus on what really helps (which IMHO is done in zshrc-mv, although perhaps auto-fu-zsh is already arguable).
However, this was discussed here earlier.
Wasn't aware of zshrc-mv. I personally don't use oh-my-zsh. It seems too big for a zshrc setup. Moreover, most of the git stuff there are quite slow. I wrote my own git related function which does not give an overwhelming amount of information, but is fast, unless you access a git directory after cold boot (~1-2sec in this case).
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
_______0
Guru
Guru


Joined: 15 Oct 2012
Posts: 521

PostPosted: Sun Jan 13, 2013 7:18 pm    Post subject: Reply with quote

ppurka wrote:
Code:
# Colors in tab completion
zstyle ':completion:*:default'          list-colors \
    'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==34=00}:${(s.:.)ZLS_COLORS}")'

There are some nice zshrc files on the web. There is zsh wiki. There is oh-my-zsh https://github.com/robbyrussell/oh-my-zsh with lots and lots of forks! :)


thanks, almost there, but is not navigable with arrowns keys like systemrescuecd.

What's ZLS_COLORS? This killed my filetype colorings :/ I change that line to LS_COLORS and still files of different types aren't being colored.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Sun Jan 13, 2013 8:23 pm    Post subject: Reply with quote

ppurka wrote:
I wrote my own git related function

zshrc-mv just takes the one from set_prompt (also in the mv overlay) which essentially does only a very quick parsing the output of git status --porcelain -sb.
The main difficulty of such a function is to avoid security issues so that nobody could trick you if you are root and "cd" to a directory with a specially crafted .git subdirectory.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Sun Jan 13, 2013 8:25 pm    Post subject: Reply with quote

_______0 wrote:
thanks, almost there, but is not navigable with arrowns keys like systemrescuecd.

This is menu mode. Try e.g. zshrc-mv which activates this and much more (including the mentioned colors).
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sun Apr 14, 2013 5:12 pm    Post subject: Reply with quote

Its probably time for some more zsh goodness, and get this thread bumped back up into the list of currently active threads.

As you may or may not know zsh has a set of "qualifiers" for globbing. These provide a means to fine grain the parameters of a command, and can aid in targeting the filetype, ownership, permissions, size, modification time, etc, etc. They can also provide a means to avoid using a call to find, and other such commands. These same qualifiers can also combined with 'zmv' (man zshcontrib |less -R +/zmv) when the -Q flag is provided, so mass moving/renaming can be done with specific qualifications on the effected targets, and without the needs for for loops and temporary files.

Some of the basic qualifiers:

/ ... directories
. ... plain files
F ... full (i.e. non-empty) directories
@ ... symbolic links
= ... sockets
p ... named pipes (FIFOs)
* ... executable plain files (0100)
% ... device files (character or block special)
%b ... block special files
%c ... character special files
r ... owner-readable files (0400)
w ... owner-writable files (0200)
x ... owner-executable files (0100)
A ... group-readable files (0040)
I ... group-writable files (0020)
E ... group-executable files (0010)
R ... world-readable files (0004)
W ... world-writable files (0002)
X ... world-executable files (0001)
s ... setuid files (04000)
S ... setgid files (02000)
t ... files with the sticky bit (01000)
e ... execute

See the manpage for the full list. (man zshexpn |less -R +/Qualifiers)

Some basic examples:

List files only

Code:
% ls *(.)

List directories only

Code:
% ls -d *(/)

List empty directories .. note how we can "not" the meaning of the above F (full)

Code:
% ls -d *(/^F)'

List files in which the user has read-write permissions and other has no read-write

Code:
% print -l *(f:u+rw,o-rw:)

Similar to the above but recursive, using the '**/*' glob, note the 'print -l' will provide a similar output as find. This time the parameter is world writable.

Code:
% print -l **/*(f:o+w:)

List the ten most recent files

Code:
% print -l *(.omN[1,10])

List all files modified today (at least, not older than one day)

Code:
% print -l **/*(.m0)

List all file owned by the group 'webusers'

Code:
% print -l **/*(g:webusers:)

List (recursively) all files larger than 100mb

Code:
% ls -hlS **/*(.Lm+100)

Make all regular (non-executable) files publicly readable, again notice that we are using "^" to "not" the meaning of 'x'.

Code:
% chmod go+r *(.^x)

Print the disk id of the first disk. Note we can use use regular modifiers along with glob modifiers, ie, :t 'tail' (again, see zshexpn for information re 'modifiers').

Code:
% print -l /dev/disk/by-id/*(@[1]:t)

We can also incorporate other commands within the qualifier, eg, 'file' to find jpegs.

Code:
% print -l *(e:'file $REPLY | grep -q JPEG':)

Hopefully your beginning to see how useful glob qualifiers can be, but as we can also combine them in various ways they can make some complex tasks simple, ie, batch renaming/moving based on criteria, first some examples of basic globbing:

Rename all .sh files to .txt using a zsh style 'for' loop (setopt short_loops)

Code:
% for f (*.sh) mv $f $f:gs/sh/txt/

The same but this time using zmv (autoload -Uz zmv)

Code:
% zmv '(*).sh' '$1.txt'

... or similarly, rename recursively all *.JPEG to *.jpeg, note how we're splitting the pattern so that '$1' (the path) and '$2' (the filename) are not misinterpreted.

Code:
% zmv '(**/)(*).JPEG' '$1$2.jpg'

... or similarly replace dots with underscores, note that again we split the match so that the dot before any .suffix (ie, *.txt) is not effected by the rename.

Code:
% zmv '(*.*)(.*)' '${1//./_}$2'

... or similarly recursively rename from upper to lower case (as we are using glob qualifiers we need to provide zmv with the -Q switch)

Code:
% zmv -Q '(**/)(*)(.)' '$1${(L)2}'

An example of zmv and glob qualifiers to rename all files with spaces in the filename, replacing the space with an underscore

Code:
% zmv -Q '(**/)* *(.D)' '$f:gs/ /_'

Yeah, quite a mouthful, but it does illustrate that globbing and qualifiers can handle many tasks that generally ... cough, cough ... bash can not (without external assistance that is).

Happy globbing & best ... khay

Resources:
strcat's unsorted misc examples
zsh-lovers manpage (app-doc/zsh-lovers)
Zzappers Best of ZSH Tips

EDIT: corrected some typos/errors, and cleaned up some descriptions


Last edited by khayyam on Mon Apr 15, 2013 7:03 am; edited 4 times in total
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1330
Location: Netherlands

PostPosted: Mon Apr 15, 2013 6:24 am    Post subject: Reply with quote

Thank you very much khayyam!

This is one of the most helpful explanations of qualifiers and their usage (!) that I've seen so far! B-)

Kindly yours
swimmer
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Mon Apr 15, 2013 2:56 pm    Post subject: Reply with quote

thank you swimmer ... but really, it could be a lot better had I spent more time, already I've gone back and made a few fixes/changes. I could (or rather should) provided some idea on simplifying zmv usage. If you read the zmv code it states ominously "to get the full power of it, you need a postgraduate degree in zsh" which is somewhat true in that '(**/)(*)' though the same as '**/*' is a change in syntax, that said, I did explain why this is (splitting the match), however, I didn't explain that the latter can be used also, with a little trickery:

Code:
% alias mmv='noglob zmv -W'
% mmv **/*.JPEG **/*.jpg

The -W switch has zsh insert the parentheses '(**/)(*)' and numbered variables '$1$2', the 'noglob' is to prevent zsh expanding the globs itself, as these are passed to zmv as 'pattern'.

This works for most purposes, but sometimes being explicit is better, because zmv isn't to know that you only want $1 when '**/*' contains two variables, so you may receive errors like the following:

Code:
% noglob zmv -CQW **/*.JPEG(.m0) ~/backup/$1.jpg
zmv: error: number of wildcards in each pattern must match
% noglob zmv -CQWnv **/*.JPEG(.m0) ~/backup/**/*.jpg
cp -- test1/1.JPEG /home/khayyam/backup/test1/1.jpg
cp -- test1/4.JPEG /home/khayyam/backup/test1/4.jpg

Note the additional switches: -C for 'cp' instead of 'mv', -n for no execution, just show what would happen, and -v for verbose, -Q we already covered, the pattern contains glob qualifiers, see man zshcontrib for a list of all the available switches.

Code:
% alias zcp='noglob zmv -CWv'
% zcp *.sh *.txt
cp -- 1.sh 1.txt
cp -- 2.sh 2.txt
% zcp -Q *.txt(g:users:) ~/backup/*-${(%):-"%D{%Y-%m-%d}"}.txt
cp -- test1.txt /home/khayyam/backup/test1-2013-04-15.txt
cp -- test2.txt /home/khayyam/backup/test2-2013-04-15.txt

Hopefully that makes some use cases a little easier to work with ...

Again, happy globbing & best ... khay
Back to top
View user's profile Send private message
_______0
Guru
Guru


Joined: 15 Oct 2012
Posts: 521

PostPosted: Mon Apr 29, 2013 3:28 pm    Post subject: Reply with quote

hi,

how to restore home/end button to not convert upper/lower case and got beginning/end line? I am using in vi mode. If there's an alternative way of doing it I could use it. Lower/upper case in promp seems rather useless.

thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Goto page Previous  1, 2, 3 ... , 11, 12, 13  Next
Page 12 of 13

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum