pimped out zsh prompt
[ link: pimping-out-zsh-prompt | tags: git zsh shell | updated: Sun, 03 Oct 2010 10:32:21 ]
Here is yet another update to the series. I've updated my git prompt again,
now using the zsh 4.3.7 built in vcs_info
module. This time the motivation came
from Zsh Prompt Magic article.
Here is what it looks like now:
Everything is now self contained in one file: S60_prompt. Grab it and source it into your zsh config.
The features are:
- name of current branch,
- git repo state (
rebase
,am
,bisect
,merge
, etc), - markers indicating staged/unstaged changes,
- little
1
after branch name indicates dirty working tree, - little
2
after branch name indicates staged changes,
- little
- highlight depth decended into the repository on the right,
- show failure of commands via prompt background change,
- show command/insert mode when using vi mode (
set -o vi
).
running really nice
[ link: 20091205130455 | tags: zsh shell | updated: Sat, 05 Dec 2009 13:16:41 ]
Everyone that uses the shell eventually learns about nice
-- the tool that runs a process at a reduced priority.
Well, there is also ionice
that allows you to tweak processes from taking over all disk IO.
I added a vnice()
function into my ZSH config so I can run or mark processes for lower priority for
both nice
and ionice
levels.
how would you read a file into an array of lines
[ link: 20090610150039 | tags: bash shell zsh | updated: Wed, 10 Jun 2009 21:34:46 ]
I was working on a shell script that needed to look at some lines in a bunch of files and perform some data mining. I started it in bash, so I am writing it in bash even though dave0 notes that I should have started in in perl. Point taken... I suffer for my mistake.
After a quick google I learned that a nice way to do what the topic of this post describes can be done using
IFS='
'
declare -a foo=( $(cat $file) )
Which is great! Right?
tiding up the PATH
[ link: 20090609000208 | tags: zsh | updated: Wed, 10 Jun 2009 15:09:17 ]
I have previously noticed that loading up the list of application available in $PATH
took a long
time in wmii-lua. I recently found out that it was related to me having multiple
duplicates in my zsh environment.
To clean this up I added the following to my zsh configuration:
typeset -U path cdpath manpath fpath
This removes duplicates from the PATH
, CDPATH
, MANPATH
, and FPATH
environment variables.
Well, technically it removes duplicates from the path
, cdpath
, manpath
, and fpath
arrays;
but these are treated special and updating them automatically generates their respective :
-delimited
environment variables.
Zsh rocks!
show more git info on zsh prompt
[ link: zsh-git-prompt | tags: git zsh shell | updated: Sun, 03 Oct 2010 10:32:21 ]
UPDATE: This post was updated (yet again).
This is my third post on the topic. I have harshly assimulated MadCoder's configuration. Here is my new zsh prompt:
UPDATE: I've updated my prompt again.
show current git branch on zsh prompt (2)
[ link: zsh-git-branch2 | tags: git zsh shell | updated: Sun, 03 Oct 2010 10:32:21 ]
NOTE: This post has been updated (again).
I previously wrote about showing the git branch name on the zsh prompt. Caio Marcelo pointed out that
it didn't work very well because the git branch was being queried before the command was executed, and it should
be after to catch git commands that change the branch, like git branch
and git checkout
.
He was right, here is a repost.
screen -c relative path bug
[ link: screen-relative-path-bug | tags: screen bug zsh | updated: Wed, 30 Apr 2008 10:42:10 ]
I must have recently upgraded to a new screen. My screenrc file was using the chdir
directive
so that the windows started inside would have a PWD I wanted them to. As soon as I tried
to reconnect the screen session would die.
screen -x
Unable to open "screenrc"
I was able to find the bug on savannah that described the symptom quite well.
I then wrote a wrapper zsh function which fixes the problem:
REAL_SCREEN=$(which screen)
# convert the path passed via the -c parameter to an absolute one
screen() {
local max=$((${#argv}-1))
for (( x=1 ; x<=$max ; x++ )) ; do
local flag="${argv[$x]}"
if [[ "x$flag" = "x-c" ]] ; then
local y=$(($x+1))
local word="${argv[$y]}"
if [[ "x${word[1]}" != 'x/' ]] ; then
argv[$y]="$PWD/$word"
fi
fi
done
echo ${REAL_SCREEN} ${1+"$argv"}
${REAL_SCREEN} ${1+"$@"}
}
show current git branch in zsh
[ link: zsh-git-branch | tags: git zsh shell | updated: Sun, 03 Oct 2010 10:32:21 ]
NOTE: This post has been updated.
Earlier today I saw a blog post titled "Git in your prompt"
which showed how to get the current git branch to display in zsh and bash. I tried it on my setup and found it really slow, probably due
having $HOME
on NFS or having big git repos or maybe not enough ram.
Anyway, after looking at some zsh docs and blog posts, I had
added caching to the idea. Now the git-branch is only queried on a directory change or on a command that matches *git*
.
zsh tip of the day - global aliases
[ link: zsh-global-alilases | tags: zsh | updated: Mon, 07 Jan 2008 16:07:08 ]
Most shells have aliases. Last week I started using a new (to me) feature in zsh aliases. Zsh lets you create arbitrary substitutions for the command line, not just the executable.
The simple example of a alias would create a new command that acts like another with some parameters added to it:
alias ll='ls -l'
You can also alias other common patterns in zsh. Say, you noticed that you used | tail -n10
a lot in your
shell. You can alias it like so:
alias -g TT10='| tail -n10"
history TT10
(10 lines follow)
You can also make this tail macro a bit more useful by not fixing it to use 10 lines:
alias -g TT='| tail -n'
history TT 10
(10 lines follow)
Of course you need to pick alias names that will not conflict with normal usage.
zsh tab completion awesomeness
[ link: zsh-tab-completion | tags: zsh shell | updated: Mon, 07 Jan 2008 16:07:08 ]
I have been using zsh for a few months. I love it. The best part of zsh is the tab completion.
Here are a few examples (note that you don't actually type in the <tab>
):