Page 2 of 3

Re: zsh hacking thread!!!

Posted: Wed Nov 27, 2013 12:26 pm
by rhowaldt
^ hmm, that's smart!

Re: zsh hacking thread!!!

Posted: Wed Nov 27, 2013 12:57 pm
by GekkoP
Pretty cool.

Re: zsh hacking thread!!!

Posted: Wed Nov 27, 2013 1:35 pm
by dkeg
@joe, nice! like the the colored ball idea for stage status

Re: zsh hacking thread!!!

Posted: Sun Dec 01, 2013 5:16 pm
by DebianJoe
@dkeg: I saw that used elsewhere and thought that it was a really interesting way to get as much info as possible without wasting space.

Re: zsh hacking thread!!!

Posted: Mon Dec 02, 2013 2:35 am
by machinebacon
I wonder how much it slows down the console - because I noticed that zsh generally is a good amount slower in processing information than other shells.

Re: zsh hacking thread!!!

Posted: Mon Dec 02, 2013 6:18 am
by DebianJoe
I can't tell a noticeable difference between a stock zsh and a highly modified one. I'm sure that there would be one, but the opening lag doesn't seem to increase (insofar as I can tell without timing it.) Zsh does take longer to load up than the other shells, certainly.

Re: zsh hacking thread!!!

Posted: Wed Dec 11, 2013 5:32 pm
by GekkoP
Put this in your .zshrc to get DEL key working as you might expect.

Code: Select all

function zle-line-init () { echoti smkx }
function zle-line-finish () { echoti rmkx }
zle -N zle-line-init
zle -N zle-line-finish
Works fine with st.
Actually, not mine. Taken from suckless, but still pretty useful. :)

Re: zsh hacking thread!!!

Posted: Fri Jan 17, 2014 4:57 pm
by GekkoP
Not a hack, but still a little fix that anyone who uses zsh with emacs mode could find useful.
When in tmux, C-a prefix conflicts with emacs mode shortcut for quickly going at the beginning of the line (a trick I'm used to in Emacs already).
Basically I did this in my .tmux.conf:

Code: Select all

set -g prefix C-o
unbind C-b
bind-key C-o send-prefix
It didn't take long the get used to this new setup and now zsh, emacs mode and tmux are a happy family.

Re: zsh hacking thread!!!

Posted: Sat Jan 18, 2014 4:06 am
by machinebacon
^ works in other shells too :)

Re: zsh hacking thread!!!

Posted: Sat Jan 18, 2014 8:26 pm
by wuxmedia
I found a similar thing, in bash + tmux, but through idiotic bashing of the keys, double ctrl a (hit 'ctrl a' then 'ctrl a' again) would bring me to the start of the line...

Re: zsh hacking thread!!!

Posted: Sun Jan 19, 2014 3:27 am
by machinebacon
^ That's actually pretty cool.

Re: zsh hacking thread!!!

Posted: Wed Feb 19, 2014 8:36 pm
by GekkoP
Since I needed a way to check my laptop battery status in JWM without using Conky or something similar, I added this to my .zshrc:

Code: Select all

precmd() {
    local BATT="$(~/bin/batt.sh)"
    RPROMPT="%{$fg_bold[green]%}Battery:%f ${BATT}%f%{$reset_color%}"
}
batt.sh is just an acpi wrapper that only gets the info I need, but real beauty is precmd that helps me keeping that battery status updated on my prompt.
Probably common knowledge, but I'm too happy with JWM to mess it up with Conky. :)

Re: zsh hacking thread!!!

Posted: Thu Feb 20, 2014 4:43 am
by machinebacon
Nice! Maybe it's possible to make a kind of embedded status in the JWM bar -- much like xload is doing now. But this would rather belong to the .jwmrc config section :D

Re: zsh hacking thread!!!

Posted: Thu Feb 20, 2014 12:12 pm
by GekkoP
Yes, I was trying to do that yesterday but then I moved to zsh and the solution came quicker. Of course, if anyone can work it out on the JWM bar please do let me know. :)

Re: zsh hacking thread!!!

Posted: Thu Feb 20, 2014 12:44 pm
by wuxmedia
wuxmedia wrote:I found a similar thing, in bash + tmux, but through idiotic bashing of the keys, double ctrl a (hit 'ctrl a' then 'ctrl a' again) would bring me to the start of the line...
Doesn't work with 'screen' though (installed on the work gateway) just tries to get through to nested sessions.

Re: zsh hacking thread!!!

Posted: Mon May 26, 2014 4:55 pm
by GekkoP
I really liked grml prompt colors. Especially the ones for user and root. Since I dropped grml zsh config (I was using only a tiny part of it) and I got my own zshrc with only the things I need, I use this to get the colors I want:

Code: Select all

# prompt colors
color="blue"
if [ "$USER" = "root" ]; then
    color="red"
fi;
prompt="%{$fg_bold[$color]%}%n%{$reset_color%}@%{$fg[white]%}%m%{$reset_color%}%u %B%~%b "
You may have already seen it in my scrots, but here's an example anyway.

Image

Re: zsh hacking thread!!!

Posted: Wed Jun 04, 2014 5:42 pm
by GekkoP
Another nice trick with zsh: multiple redirection.

Code: Select all

echo "test1" >file1
echo "test2" >file2
echo "test3" >>file1 >>file2 >file3
cat file[1-3]
test1
test3
test2
test3
test3

Re: zsh hacking thread!!!

Posted: Thu Aug 14, 2014 2:02 pm
by GekkoP
Fine-tuning moving/renaming files with zmv.

Add this to your .zshrc:

Code: Select all

autoload -Uz zmv
Source .zshrc and enjoy a better moving/renaming. For instance:

Code: Select all

manuel@bebop ~/tmp ls
test_1    test_2    test_3

manuel@bebop ~/tmp zmv 'test_(*)' '$1'
manuel@bebop ~/tmp ls
1    2    3

Re: zsh hacking thread!!!

Posted: Fri Aug 14, 2015 2:47 pm
by GekkoP
Adding a completion mechanism to zsh:

Code: Select all

# load function-based completion system
autoload -Uz compinit && compinit
zstyle ':completion:*' verbose yes
Image


Adding a pager (like less/more):

Code: Select all

# use a pager to scroll long ouput
zmodload zsh/complist
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
# use 'q' to exit the pager
bindkey -M listscroll q send-break
Image


A custom chown with autocompletion:

Code: Select all

_chown() {
    local ret=1
    local -a suf

    if (( CURRENT == 2)); then
        if compset -P '*[.:]'; then
            _groups && ret=0
        else
            compset -S '[.:]*' || suf=( -S . )
            _users "$suf[@]" && ret=0
        fi
    else
        _files && ret=0
    fi

    return ret
}
compdef _chown chown
Image


This magic comes straight from this highly recommended book:

Image

Re: zsh hacking thread!!!

Posted: Sun Aug 16, 2015 9:21 am
by GekkoP
Handy functions to cd back up to the highest level of your git repository dir

Code: Select all

function cds {
    ORIGINAL_PWD=`pwd`
    while [ ! -d ".git" -a `pwd` != "/" ]
    do
        cd ..
    done
    if [ ! -d ".git" ]
    then
        cd $ORIGINAL_PWD
    fi
}