Posts for: #Zsh

pimped out zsh prompt

Here is [yet another]{zsh-git-prompt} 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:

zsh git prompt

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,
  • 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).
Read more →

running really nice

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.

Read more →

how would you read a file into an array of lines

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?

Read more →

tiding up the PATH

I have previously noticed that loading up the list of application available in $PATH took a long time in [wmii-lua]{tag/wmiirc-lua}. I recently found out that it was related to me having multiple duplicates in my [zsh]{tag/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.

Read more →

show current git branch on zsh prompt (2)

NOTE: This post has been [updated]{zsh-git-prompt} (again).

I previously wrote about [showing the git branch name on the zsh prompt]{zsh-git-branch}. 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.

Read more →

screen -c relative path bug

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:

Read more →

show current git branch in zsh

NOTE: This post has been [updated]{zsh-git-branch2}.

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*.

Read more →

zsh tip of the day - global aliases

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.

Read more →

zsh tab completion awesomeness

I have been using [zsh]{tag/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>):

Read more →