zsh hacking thread!!!
Forum rules
Share your brain ;)
Share your brain ;)
Re: zsh hacking thread!!!
^ hmm, that's smart!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.
Re: zsh hacking thread!!!
Pretty cool.
Re: zsh hacking thread!!!
@joe, nice! like the the colored ball idea for stage status
Work hard; Complain less
Re: zsh hacking thread!!!
@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.
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: zsh hacking thread!!!
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.
..gnutella..
Re: zsh hacking thread!!!
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!!!
Put this in your .zshrc to get DEL key working as you might expect.
Works fine with st.
Actually, not mine. Taken from suckless, but still pretty useful. :)
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
Actually, not mine. Taken from suckless, but still pretty useful. :)
Re: zsh hacking thread!!!
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:
It didn't take long the get used to this new setup and now zsh, emacs mode and tmux are a happy family.
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
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
- wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: zsh hacking thread!!!
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...
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: zsh hacking thread!!!
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:
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. :)
Code: Select all
precmd() {
local BATT="$(~/bin/batt.sh)"
RPROMPT="%{$fg_bold[green]%}Battery:%f ${BATT}%f%{$reset_color%}"
}
Probably common knowledge, but I'm too happy with JWM to mess it up with Conky. :)
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: zsh hacking thread!!!
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
..gnutella..
Re: zsh hacking thread!!!
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. :)
- wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: zsh hacking thread!!!
Doesn't work with 'screen' though (installed on the work gateway) just tries to get through to nested sessions.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...
Re: zsh hacking thread!!!
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:
You may have already seen it in my scrots, but here's an example anyway.
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 "
Re: zsh hacking thread!!!
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!!!
Fine-tuning moving/renaming files with zmv.
Add this to your .zshrc:
Source .zshrc and enjoy a better moving/renaming. For instance:
Add this to your .zshrc:
Code: Select all
autoload -Uz zmv
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!!!
Adding a completion mechanism to zsh:
Adding a pager (like less/more):
A custom chown with autocompletion:
This magic comes straight from this highly recommended book:
Code: Select all
# load function-based completion system
autoload -Uz compinit && compinit
zstyle ':completion:*' verbose yes
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
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
This magic comes straight from this highly recommended book:
Re: zsh hacking thread!!!
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
}