You are not logged in.

#1 2007-06-12 00:00:41

Borosai
Member
From: Sandy Appendix, U.S.A.
Registered: 2006-06-15
Posts: 227

Zsh(rc) Tips Thread

Like the title says, I think it would be a great idea to share some of the more useful options available for zsh. I feel comfortable with my current configuration, but I know there are plenty of aspects of the shell I haven't touched. So, if anyone has any great tips that make using zsh even better, please share.

I am posting my current .zshrc just as a starting point. smile

export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/opt/mozilla/bin"
export EDITOR="vim"

autoload -U compinit
compinit

bindkey    "\e[7~"    beginning-of-line
bindkey    "\e[8~"    end-of-line
bindkey    "\e[3~"    delete-char

HISTFILE=~/.zshhistory
HISTSIZE=1024
SAVEHIST=1024

# Color Format
# %{\e[*;**m%}
# %{\e[0m%}
# Default Prompt = '[%n@%m] [%~] %# '

PROMPT=$'[%{\e[1;37m%}%n%{\e[0m%}]%# '
RPROMPT=$'[%m : %~]'

setopt    GLOB
setopt    EXTENDED_HISTORY
setopt    INC_APPEND_HISTORY
setopt    SHARE_HISTORY
setopt    HIST_IGNORE_DUPS
setopt    HIST_FIND_NO_DUPS
setopt    HIST_IGNORE_SPACE
setopt    HIST_VERIFY
setopt    NO_HIST_BEEP
setopt    NO_BEEP
setopt    NO_HUP

alias    ..='cd ..'
alias    cl='clear'
alias    ls='ls -A --color=auto'
alias    lsl='ls -l --color=auto'
alias    lso='ls -1 --color=auto'
alias    lsr='ls -R --color=auto'
alias    rm='rm -i'
alias    gvim='gvim -geom 90x45'

alias    -g    L='|less'
alias    -g    G='|grep'

Offline

#2 2007-06-12 17:59:54

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Zsh(rc) Tips Thread

There's probably a lot of cruft in here; I haven't cleaned it out in a while. Still, I try to keep it commented and there are some useful things.

# .zshrc

# by Mark Taylor <skymt0@gmail.com>

# {{{ Host-specific initialization

# I use ZSH on two seperate machines. rincewind runs Arch Linux, while
# twoflower is a Mac running Mac OS X. Because of the differences between
# platforms, I need to customize my shell differently on each. A simple case
# block does the job well enough.

case ${HOST:r} in
    (rincewind)
    alias ls='ls --color=auto' # ensure colorized listings
    export PAGER='most'
    export MANPAGER=most
    ;;
    (twoflower)
    alias ls='ls -G'
    ;;
esac

# }}}

# {{{ Functions

# maybe() asks me if I'm *really* sure I want to run that command.  Nice
# comprimise between the default rm and rm -i.

maybe() {
    command=$1
    shift
    echo $@ | xargs -r -p ${=command}
}

# title_clock displays a clock in the titlebar. It's cool.

title_clock() {
    while true ; do
    set_xterm_title `date`
    sleep 1
    done
}

# lcfiles() lowercases all files in the current directory. Not useful on a
# day-to-day basis, but when you need it, you *really* need it.

# It's also a good example of how powerful ZSH is. Just tack on :l to
# lower-case anything.

lcfiles() {
    print -n 'Really lowercase all files? (yn) '
    if read -q ; then
    for i in * ; do
        mv $i $i:l
    done
    fi
}

# all() takes a command and a list of files, then runs the command on each
# file. It's great shorthand for a clumsy for loop.

all() {
    todo=$argv[1]
    argv[1]=""

    echo $@ | xargs --no-run-if-empty --verbose --max-args=1 ${=todo}
}

# set_xterm_title() sets the title of an xterm. It's now terminfo-enabled.
# While this is the "right way", it also means you need a sane terminfo entry
# for your terminal.

THSTATUS=`tput tsl`
FHSTATUS=`tput fsl`

set_xterm_title() {
    if tput hs ; then
    print -Pn "$THSTATUS$@$LOCAL_CUSTOM_HARDSTATUS$FHSTATUS"
    fi
}

tag() {
    if [ $# -eq 0 ] ; then
    LOCAL_CUSTOM_HARDSTATUS=""
    else
    LOCAL_CUSTOM_HARDSTATUS=" - $@"
    fi
}

# preexec() runs before each command. The command line used to run the program
# is $1. That allows this hack, which shows the name of whatever command is
# currently running, directly in the titlebar.

preexec() {
    set_xterm_title "%n@%m: %50>...>$1%<<"
}

# ZSH runs precmd() before each prompt. Because of the above preexec hack, I
# use it to display the pwd in the titlebar. Most people use chpwd for this,
# which is a bit more efficient, but that obviously wouldn't work in this case.

precmd() {
    set_xterm_title "%n@%m: %50<...<%~%<<"
}

# Here are a few compression shortcuts

tg() {
    tarfile=$1
    shift
    tar -czvf $tarfile $@
}

tb() {
    tarfile=$1
    shift
    tar --bzip2 -cvf $tarfile $@
}

tgd() {
    tar -czvf $1.tar.gz $1
}

tbd() {
    tar --bzip2 -cvf $1.tar.bz2 $1
}

# }}}

# {{{ Aliases

# Globals, for redirection
alias -g :g='| grep' # Easy grepping
alias -g :p='| $PAGER' # Easy piping one
alias -g :sp='| sort | $PAGER' # Easy piping two
alias -g :n='&> /dev/null' # Easy piping to /dev/null
alias -g :sn='1> /dev/null' # See above
alias -g :en='2> /dev/null' # Ditto

# Default options
alias du='du -h'
alias grep='LANG=C grep' # faster than unicode, used for source so no loss
alias xfer='pilot-xfer -p /dev/pilot'
alias rtorrent='dtach -A ~/.dtach/rtorrent rtorrent -s ~/.rtorrentsession'

# ls hacks
alias la='ls -a' # List All
alias ll='ls -l' # Long Listing
alias lsa='ls -ld .*' # List only dotfiles
alias lsbig='ls -lSh *(.) | head' # List biggest
alias lsd='ls -ld *(-/DN)' # List only directories and links to them
alias lsnew='ls -lrt *(.) | tail' # List newest
alias lsold='ls -lrt *(.) | head' # List oldest
alias lssmall='ls -lSh *(.) | head' # List smallest

# Globbing workarounds
alias mmv='noglob zmv -W' # Noglob, so zmv gets wildchars (mmv = mass move)
alias ri='noglob ri' # Some chars used in ruby classes are globbing chars

# Compression shortcuts
alias t="tar -xvf"

# cd shortcuts
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'

# }}}

# {{{ Prompt

# Load colors function to make prompts (less un-) readable.
autoload colors
colors
    
# Start with a blank slate...
PROMPT=""

# ...collect the parts to use...
set -A prompt_array \
    "%{$fg[green]%}%n%{$reset_color%}" \
    "@" \
    "%{$fg[green]%}%m%{$reset_color%}" \
    "%0(?..[%{$fg[red]%}%?%{$reset_color%}])" \
    "%# "

# ...and put them all together!
for i in $prompt_array; do
    PROMPT=${PROMPT}${i}
done

# I don't need such a fancy method for making my right prompt, as it's
# much smaller and monochromatic.
RPROMPT='(%30<...<%3.%<<%) %D{%I:%M}'

# }}}

# {{{ Options and variables

setopt auto_cd            # automatically cd to paths
setopt brace_ccl            # expand alphabetic brace expressions
setopt chase_links          # ~/ln -> /; cd ln; pwd -> /
setopt complete_in_word     # ~/Dev/pro -> <Tab> -> ~/Development/project
setopt correct              # spell check for commands only
setopt dvorak               # use spelling correction for dv keyboards
setopt equals extended_glob # use extra globbing operators
setopt hash_list_all        # search all paths before command completion
setopt hist_ignore_dups     # when I run a command several times, only store one
setopt hist_no_functions    # don't show function definitions in history
setopt hist_reduce_blanks   # reduce whitespace in history
setopt hist_verify          # ask me before running a command line with history sub
setopt interactive_comments # why not?
setopt list_types           # show ls -F style marks in file completion
setopt no_beep              # don't beep on error
setopt numeric_glob_sort    # when globbing numbered files, use real counting

export ALEPHONE_DATA=.
export MAILPATH=~/incoming/mail

# Store 1000 previous commands
HISTSIZE=1000

# Notice that I didn't set a history file. That's intentional. I don't
# like history files. They seem pointless to me, plus the order can be
# confusing when using lots of shells (screen, multiple xterms, etc).

# }}}

# {{{ Everything else

# ZMV can be useful at times
autoload -U zmv

#bindkey -v # use vi keymap
bindkey -e # use emacs keymap

# This is missing from the emacs keymap, but not from the vi one
#bindkey '^Xh' _complete_help

# Fix Emacs shell-mode
#[[ $EMACS = t ]] && unsetopt zle

# Make sure ZLE doesn't get confused about all the fancy formatting above
# (without this, it does around 20% of the time, in my experience)
reset

# gpg-agent says it needs this
export GPG_TTY=`tty`

# simple typing shortcut
svnr='file:///home/mark/.svnr'

# }}}

# {{{ Completion
# The following lines were added by compinstall

zstyle ':completion:*' completer _expand _complete _approximate
zstyle ':completion:*' completions 1
zstyle ':completion:*' format '%d:'
zstyle ':completion:*' glob 1
zstyle ':completion:*' group-name ''
zstyle ':completion:*' ignore-parents parent pwd ..
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' max-errors 0 numeric
zstyle ':completion:*' menu select=15
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle ':completion:*' prompt '%e errors> '
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' substitute 1
zstyle ':completion:*' use-compctl true
zstyle ':completion:*' verbose true
zstyle :compinstall filename '/home/mark/.zsh/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall
# }}}

# Some hacks for dumb terms
if [ $TERM = dumb ] ; then
    unalias ls
    PROMPT="> "
fi

Offline

#3 2007-06-12 19:44:26

Borosai
Member
From: Sandy Appendix, U.S.A.
Registered: 2006-06-15
Posts: 227

Re: Zsh(rc) Tips Thread

Wow... that's extensive, but commented very well. smile

Offline

#4 2007-06-12 21:28:22

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Zsh(rc) Tips Thread

My /etc/zsh/zshrc, compiled from other rcs floating around the net.

alias dh='dirs -v'
alias ls='ls --color=always'
#alias makepkg='schedtool -D -e makepkg'
#alias versionpkg='schedtool -D -e versionpkg'
setopt AUTOLIST AUTOCD CORRECT EXTENDEDGLOB NOCLOBBER AUTOPUSHD PUSHDMINUS PUSHDSILENT PUSHDTOHOME PUSHD_IGNORE_DUPS NOBEEP HIST_SAVE_NO_DUPS HIST_FIND_NO_DUPS APPEND_HISTORY SHARE_HISTORY NOBANGHIST NOTIFY ALWAYS_TO_END COMPLETE_IN_WORD
unset MAILCHECK

bindkey "" delete-char                         # Delete
bindkey "" beginning-of-line                    # Home (linux)
bindkey ""  end-of-line                         # End (linux)
bindkey ""  history-beginning-search-backward  # Page Up
bindkey ""  history-beginning-search-forward   # Page Down
bindkey "" overwrite-mode                      # Insert

export LS_COLORS='*.swp=-1;44;37:*,v=5;34;93:*.vim=35:no=0:fi=0:di=32:ln=36:or=1;40:mi=1;40:pi=31:so=33:bd=44;37:cd=44;37:*.jpg=1;32:*.jpeg=1;32:*.JPG=1;32:*.gif=1;32:*.png=1;32:*.jpeg=1;32:*.ppm=1;32:*.pgm=1;32:*.pbm=1;32:*.c=1;32:*.C=1;33:*.h=1;33:*.cc=1;33:*.awk=1;33:*.pl=1;33:*.gz=0;33:*.tar=0;33:*.zip=0;33:*.lha=0;33:*.lzh=0;33:*.arj=0;33:*.bz2=0;33:*.tgz=0;33:*.taz=33:*.html=36:*.htm=1;34:*.doc=1;34:*.txt=1;34:*.o=1;36:*.a=1;36'
export ZLS_COLORS='*.swp=00;44;37:*,v=5;34;93:*.vim=35:no=0:fi=0:di=32:ln=36:or=1;40:mi=1;40:pi=31:so=33:bd=44;37:cd=44;37:*.jpg=1;32:*.jpeg=1;32:*.JPG=1;32:*.gif=1;32:*.png=1;32:*.jpeg=1;32:*.ppm=1;32:*.pgm=1;32:*.pbm=1;32:*.c=1;32:*.C=1;33:*.h=1;33:*.cc=1;33:*.awk=1;33:*.pl=1;33:*.gz=0;33:*.tar=0;33:*.zip=0;33:*.lha=0;33:*.lzh=0;33:*.arj=0;33:*.bz2=0;33:*.tgz=0;33:*.taz=33:*.html=36:*.htm=1;34:*.doc=1;34:*.txt=1;34:*.o=1;36:*.a=1;36'
export CLICOLOR=1       # some shells need this to enable colorized out
export GREP_COLOR=32    # some greps have colorized ouput. enable...
export GREPCOLOR=32     # dito here

autoload -U zsh-mime-setup
zsh-mime-setup

TIMEFMT="Real: %E User: %U System: %S Percent: %P Cmd: %J"
HISTSIZE=100000
HISTFILE=$HOME/.zsh_history
SAVEHIST=65536
DIRSTACKSIZE=10

readonly HISTFILE
readonly HISTLOG
readonly HISTSAVE


function mcd() { mkdir "$@"; cd "$@" }
function cl() { cd $1 && ls -a }
alias .='cd ..'
alias ..='cd ../../'
alias ...='cd ../../../'

autoload -U compinit
compinit
autoload zmv
zmodload zsh/complist

zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*})
zstyle ':completion:*:(ssh|scp):*' hosts $hosts
#zstyle ':completion:*:(ssh|scp):*' users $users
#zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
#zstyle ':completion:*:warnings' format '%BSorry. No match for: %d%b'
#zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
#zstyle ':completion:*' group-name ''

# Usage: extract <file>
# Description: extracts archived files (maybe)
extract () {
    if [ -f $1 ]; then
            case $1 in
            *.tar.bz2)  tar -jxvf $1        ;;
            *.tar.gz)   tar -zxvf $1        ;;
            *.bz2)      bzip2 -d $1         ;;
            *.gz)       gunzip -d $1        ;;
            *.tar)      tar -xvf $1         ;;
            *.tgz)      tar -zxvf $1        ;;
            *.zip)      unzip $1            ;;
            *.Z)        uncompress $1       ;;
            *.rar)      unrar x $1            ;;
            *)          echo "'$1' Error. Please go away" ;;
            esac
            else
            echo "'$1' is not a valid file"
  fi
  }

# Usage: show-archive <archive>
# Description: view archive without unpack
show-archive() {
   if [ -f $1 ]; then
         case $1 in
         *.tar.bz2)     tar -jtf $1 ;;
         *.tar.gz)      tar -ztf $1 ;;
         *.tar)         tar -tf $1  ;;
         *.tgz)         tar -ztf $1 ;;
         *.zip)         unzip -l $1 ;;
         *.rar)         rar vb $1   ;;
         *)             echo "'$1' Error. Please go away" ;;
         esac
         else
         echo "'$1' is not a valid archive"
  fi
  }

compctl -g '*.tar.Z *.tar.gz *.tgz *.zip *.ZIP *.tar.bz2 *.rar' + -g '*'  show-archive extract
compctl -g '*.pkg.tar.gz' + -g '*' pacman -U
compctl -g '*.pkg.tar.gz' + -g '*' sudo pacman -U

# Nicer kill completion
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:kill:*' insert-ids single
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always

Offline

#5 2007-07-03 16:59:46

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: Zsh(rc) Tips Thread

I would really like to see screenshots of the different configs.. to lazy to try them all out big_smile


The ultimate Archlinux release name: "I am your father"

Offline

#6 2007-07-03 19:00:38

Mefju
Member
From: Poland
Registered: 2006-07-12
Posts: 104

Re: Zsh(rc) Tips Thread

My .zshrc

#################################################
#
#    Z Shell configuration file
#
#    version 12
#
#################################################


################## ZSH OPTIONS ##################
setopt auto_cd
setopt cd_able_vars
setopt extended_glob
setopt correct
setopt check_jobs
setopt multios
setopt no_beep

autoload -U zmv
autoload -U colors && colors

umask 022
#################################################


################## VARIABLES ####################
path=($path ~/bin)
cdpath=(~/mp3)

for color in white red green blue yellow; do
    eval $color='%{$terminfo[bold]$fg[${color}]%}'
done
nocolor="%{$terminfo[sgr0]%}"

export EDITOR="vim"
export OOO_FORCE_DESKTOP="gnome"
export WM="fvwm-crystal"
#################################################


################## ALIASES ######################
case $OSTYPE in
    linux*)
        alias ls='ls -h --color=always'
        ;;

    freebsd*)
        alias ls='ls -Gh'
        alias pkg_delete='pkg_delete -drv'
        alias portaudit-get='portaudit -Fd'
        alias portupdate='cvsup -L 2 /etc/ports-supfile'
        alias poweroff='shutdown -p now'
        ;;
esac

alias .='source'
alias backup-daily='sysbkp -si -ui'
alias backup-weekly='sysbkp -sf -uf'
alias df='df -h'
alias du='du -h'
alias file-sgid="print -c /**/*(S)"
alias file-suid="print -c /**/*(s)"
alias la='ls -a'
alias ll='ls -l'
alias lla='ls -la'
alias vi="vim"
#################################################


################# FUNCTIONS ######################
_force_rehash()
{
    (( CURRENT == 1 )) && rehash
    return 1
}
#-----------------------
if_not_loaded()
{
    module=$(zmodload -L | grep $1)
    
    if [[ -z $module ]]; then
        return 0
    else
        return 1
    fi
}
#-----------------------
account-nopass()
{
    case $OSTYPE in
        linux*)
            passwd_file="/etc/shadow"
            ;;
        freebsd*)
            passwd_file="/etc/master.passwd"
            ;;
    esac
    
    awk -F: '$2 == "" { print $1, "does not have password!" }' $passwd_file
}
#-----------------------
account-root()
{
    awk -F: '$3 == 0 { print $1, "has root privileges!" }' /etc/passwd
}
#################################################


################### HISTORY #####################
setopt append_history
setopt no_hist_beep
setopt hist_ignore_all_dups
setopt hist_ignore_space

HISTFILE=~/.zshhistory
HISTSIZE=1000
SAVEHIST=1000
#################################################


################### PROMPT ######################
setopt prompt_subst

if [[ $UID == 0 ]]; then
    PS1="${white}[${blue}%T ${red}%n ${blue}%1~${white}]%#${nocolor} "
else
    PS1="${white}[${blue}%T ${green}%n ${blue}%1~${white}]%#${nocolor} "
fi
#################################################


################### KEYBINDINGS #################
bindkey -e

case $TERM in
        linux)
        bindkey "^[[1~" beginning-of-line       # Home
        bindkey "^[[4~" end-of-line             # End 
        bindkey "^[[3~" delete-char             # Del
        bindkey "^[[2~" overwrite-mode          # Insert 
        bindkey "^[[5~" history-search-backward # PgUp 
        bindkey "^[[6~" history-search-forward  # PgDn
        ;;

    xterm)
        bindkey "^[OH"  beginning-of-line       # Home
        bindkey "^[OF"  end-of-line             # End 
        bindkey "^[[3~" delete-char             # Del
        bindkey "^[[2~" overwrite-mode          # Insert 
        bindkey "^[[5~" history-search-backward # PgUp 
        bindkey "^[[6~" history-search-forward  # PgDn
        ;;
        
    cons25l2)
        bindkey "^[[H"  beginning-of-line       # Home
        bindkey "^[[F"  end-of-line             # End 
        bindkey "^?"    delete-char             # Del
        bindkey "^[[L"  overwrite-mode          # Insert 
        bindkey "^[[I"  history-search-backward # PgUp 
        bindkey "^[[G"  history-search-forward  # PgDn
        ;;
esac
#################################################


################## COMPLETION ###################
setopt always_to_end
setopt complete_in_word
setopt list_packed
setopt no_menu_complete

autoload -U compinit && compinit
if_not_loaded zsh/complist && zmodload zsh/complist

# general completion technique
zstyle ':completion:*' completer \
    _force_rehash _complete _list _oldlist _expand _ignored _match \
    _correct _approximate _prefix

# completion caching
zstyle ':completion:*' use-cache 'yes'
zstyle ':completion:*' cache-path ~/.zshcache

# completion with globbing
zstyle ':completion:*' glob 'yes'

# selecting completion by cursor
zstyle ':completion:*' menu select=long-list select=3

# colors in completion
case $OSTYPE in
    linux*)
        eval $(dircolors)
        ;;
    freebsd*)
        LS_COLORS=$colour
        ;;
esac
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}

# formatting and messages
zstyle ':completion:*' verbose 'yes'
zstyle ':completion:*:descriptions' format "%B-- %d --%b"
zstyle ':completion:*:messages' format "%B--${green} %d ${nocolor}--%b"
zstyle ':completion:*:warnings' format "%B--${red} no match for: %d ${nocolor}--%b"
zstyle ':completion:*:corrections' format "%B--${yellow} %d ${nocolor}-- (errors %e)%b"
zstyle ':completion:*' group-name ''

# show sections in manuals
zstyle ':completion:*:manuals' separate-sections 'yes'

# describe options
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d' 

# ignore completion functions (until the _ignored completer)
zstyle ':completion:*:functions' ignored-patterns '_*'

# don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
#################################################

Offline

#7 2007-07-03 21:47:09

Borosai
Member
From: Sandy Appendix, U.S.A.
Registered: 2006-06-15
Posts: 227

Re: Zsh(rc) Tips Thread

I definitely need to get around to reading the zsh documentation. I've noticed there are a lot of features I haven't tried yet. smile

jinn wrote:

I would really like to see screenshots of the different configs.. to lazy to try them all out big_smile

I assume you are referring to the prompts right? I'm not sure what else can be shown in a screenshot as far as a shell goes. If the prompt is indeed what you want, then here it is:

oburxvtzsheh6.th.png

Very simple setup for me. The user's name on the left, and the full address on the right ( [hostname: /current/dir] ). It works for me. big_smile

Offline

#8 2007-07-07 12:32:53

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: Zsh(rc) Tips Thread

thats nice. My zsh is also like that, but the coloring is just a little different. Thanks for the screenshot.


The ultimate Archlinux release name: "I am your father"

Offline

#9 2007-07-21 04:25:42

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Zsh(rc) Tips Thread

zsh looks fun, but I feel comfortable with bash already. Try and sell me zsh. I read the website a bit and it looks great, but I'll need some convicning before I spend the effort of learning how to use it!

Offline

#10 2007-07-21 08:11:40

F
Member
Registered: 2006-10-09
Posts: 322

Re: Zsh(rc) Tips Thread

Mefju your functions and completion sections seriously rocks in my shell now.

Thanks. smile

Offline

#11 2007-07-21 09:44:52

Mefju
Member
From: Poland
Registered: 2006-07-12
Posts: 104

Re: Zsh(rc) Tips Thread

I have updated a bit my config file

#################################################
#
#    Z Shell configuration file
#
#    version 13
#
#################################################


################## ZSH OPTIONS ##################
setopt auto_cd
setopt cd_able_vars
setopt extended_glob
setopt correct
setopt check_jobs
setopt multios
setopt no_beep

autoload -U zmv
autoload -U colors && colors

umask 022
#################################################


################## VARIABLES ####################
path=($path ~/bin)
cdpath=(~/mp3)

for color in white red green blue yellow; do
    eval $color='%{$terminfo[bold]$fg[${color}]%}'
done
nocolor="%{$terminfo[sgr0]%}"

export EDITOR="vim"
export OOO_FORCE_DESKTOP="gnome"
export WM="ratpoison"
#################################################


################## ALIASES ######################
case $OSTYPE in
    linux*)
        alias ls='ls -h --color=always'
        alias xargs='xargs -r'
        ;;

    freebsd*)
        alias ls='ls -Gh'
        alias pkg_delete='pkg_delete -drv'
        alias portaudit-get='portaudit -Fd'
        alias portupdate='cvsup -L 2 /etc/ports-supfile'
        alias poweroff='shutdown -p now'
        ;;
esac

alias .='source'
alias backup-daily='sysbkp -si -ui'
alias backup-weekly='sysbkp -sf -uf'
alias df='df -h'
alias du='du -h'
alias file-sgid='print -c /**/*(S)'
alias file-suid='print -c /**/*(s)'
alias head='head -n20'
alias la='ls -a'
alias ll='ls -l'
alias lla='ls -la'
alias tail='tail -n20'
alias vi='vim'

alias -g ...='../..'
alias -g ....='../../..'
alias -g G='| grep'
alias -g H='| head'
alias -g L='| less'
alias -g N='> /dev/null'
alias -g M='| more'
alias -g T='| tail'
alias -g X='| xargs'

alias -s avi='mplayer'
alias -s c='vim'
alias -s h='vim'
alias -s htm='elinks'
alias -s html='elinks'
alias -s jpg='eog'
alias -s jpeg='eog'
alias -s mpg='mplayer'
alias -s png='eog'
alias -s py='vim'
alias -s txt='vim'
alias -s wmv='mplayer'
#################################################


################# FUNCTIONS ######################
_force_rehash()
{
    (( CURRENT == 1 )) && rehash
    return 1
}
#-----------------------
account-nopass()
{
    case $OSTYPE in
        linux*)
            passwd_file="/etc/shadow"
            ;;
        freebsd*)
            passwd_file="/etc/master.passwd"
            ;;
    esac
    
    awk -F: '$2 == "" { print $1, "does not have password!" }' $passwd_file
}
#-----------------------
account-root()
{
    awk -F: '$3 == 0 { print $1, "has root privileges!" }' /etc/passwd
}
#################################################


################### HISTORY #####################
setopt append_history
setopt no_hist_beep
setopt hist_ignore_all_dups
setopt hist_ignore_space

HISTFILE=~/.zshhistory
HISTSIZE=1000
SAVEHIST=1000
#################################################


################### PROMPT ######################
setopt prompt_subst

if [[ $UID == 0 ]]; then
    PS1="${white}[${blue}%T ${red}%n ${blue}%1~${white}]%#${nocolor} "
else
    PS1="${white}[${blue}%T ${green}%n ${blue}%1~${white}]%#${nocolor} "
fi
#################################################


################### KEYBINDINGS #################
bindkey -e

case $TERM in
    linux)
        bindkey "^[[1~" beginning-of-line       # Home
        bindkey "^[[4~" end-of-line             # End 
        bindkey "^[[3~" delete-char             # Del
        bindkey "^[[2~" overwrite-mode          # Insert 
        bindkey "^[[5~" history-search-backward # PgUp 
        bindkey "^[[6~" history-search-forward  # PgDn
        ;;

    xterm)
        bindkey "^[OH"  beginning-of-line       # Home
        bindkey "^[OF"  end-of-line             # End 
        bindkey "^[[3~" delete-char             # Del
        bindkey "^[[2~" overwrite-mode          # Insert 
        bindkey "^[[5~" history-search-backward # PgUp 
        bindkey "^[[6~" history-search-forward  # PgDn
        ;;
        
    cons25l2)
        bindkey "^[[H"  beginning-of-line       # Home
        bindkey "^[[F"  end-of-line             # End 
        bindkey "^?"    delete-char             # Del
        bindkey "^[[L"  overwrite-mode          # Insert 
        bindkey "^[[I"  history-search-backward # PgUp 
        bindkey "^[[G"  history-search-forward  # PgDn
        ;;
esac
#################################################


################## COMPLETION ###################
setopt always_to_end
setopt complete_in_word
setopt list_packed
setopt no_menu_complete

autoload -U compinit && compinit
zmodload -i zsh/complist

# general completion technique
zstyle ':completion:*' completer \
    _force_rehash _ignored _expand _complete _match _prefix _correct _approximate

# completion caching
zstyle ':completion:*' use-cache 'yes'
zstyle ':completion:*' cache-path ~/.zshcache

# completion with globbing
zstyle ':completion:*' glob 'yes'

# selecting completion by cursor
zstyle ':completion:*' menu select=long-list select=3

# colors in completion
case $OSTYPE in
    linux*)
        eval $(dircolors)
        zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
        ;;
    freebsd*)
        zstyle ':completion:*' list-colors ''
        ;;
esac

# formatting and messages
zstyle ':completion:*' verbose 'yes'
zstyle ':completion:*:descriptions' format "%B-- %d --%b"
zstyle ':completion:*:messages' format "%B--${green} %d ${nocolor}--%b"
zstyle ':completion:*:warnings' format "%B--${red} no match for: %d ${nocolor}--%b"
zstyle ':completion:*:corrections' format "%B--${yellow} %d  (errors %e)${nocolor}--%b"
zstyle ':completion:*' group-name ''

# show sections in manuals
zstyle ':completion:*:manuals' separate-sections 'yes'

# describe options
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d' 

# ignore completion functions (until the _ignored completer)
zstyle ':completion:*:functions' ignored-patterns '_*'
#################################################

Offline

#12 2007-07-21 19:41:11

F
Member
Registered: 2006-10-09
Posts: 322

Re: Zsh(rc) Tips Thread

I suppose its only fair to share mine, however some of it is taken from Mefju (its obvious which parts ;p).

PS1="[%n|%~]%% "

alias 'ls'='ls --color -hFs'
alias 'irssi'='screen irssi'
alias '..'='cd ..'

export EDITOR="vim"

setopt nobeep

PATH="$PATH:/opt/openoffice/program"
PATH="$PATH:/usr/local/bin"

# So PERL stops complaining
export LC_ALL=C
export LANG=C


#export DISPLAY=scyther:0 wmii
 
# The following lines were added by compinstall

zstyle ':completion:*' completer _expand _complete _ignored _match _correct _approximate
zstyle :compinstall filename '/home/f/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -e
# End of lines configured by zsh-newuser-install

################ FUNCTIONS ######################
_force_rehash()
{
        (( CURRENT == 1 )) && rehash
        return 1
}
#-----------------------
if_not_loaded()
{
        module=$(zmodload -L | grep $1)

        if [[ -z $module ]]; then
                return 0
        else
        return 1
        fi
}
#-----------------------
account-nopass()
{
        case $OSTYPE in
                linux*)
                        passwd_file="/etc/shadow"
                        ;;
                freebsd*)
                        passwd_file="/etc/master.passwd"
                        ;;
        esac

        awk -F: '$2 == "" { print $1, "does not have password!" }' $passwd_file
}
#-----------------------
account-root()
{
        awk -F: '$3 == 0 { print $1, "has root privileges!" }' /etc/passwd
}

################ COMPLETION ###################
setopt always_to_end
setopt complete_in_word
setopt list_packed
setopt no_menu_complete

autoload -U compinit && compinit
if_not_loaded zsh/complist && zmodload zsh/complist

# general completion technique
zstyle ':completion:*' completer \
 _force_rehash _complete _list _oldlist _expand _ignored _match \
 _correct _approximate _prefix

# completion caching
zstyle ':completion:*' use-cache 'yes'
zstyle ':completion:*' cache-path ~/.zshcache

# completion with globbing
zstyle ':completion:*' glob 'yes'

# selecting completion by cursor
zstyle ':completion:*' menu select=long-list select=3

# colors in completion
case $OSTYPE in
        linux*)
                eval $(dircolors)
                        ;;
        freebsd*)
                LS_COLORS=$colour
                ;;
               esac
               zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}

# formatting and messages
zstyle ':completion:*' verbose 'yes'
zstyle ':completion:*:descriptions' format "%B-- %d --%b"
zstyle ':completion:*:messages' format "%B--${green} %d ${nocolor}--%b"
zstyle ':completion:*:warnings' format "%B--${red} no match for: %d ${nocolor}--%b"
zstyle ':completion:*:corrections' format "%B--${yellow} %d ${nocolor}-- (errors %e)%b"
zstyle ':completion:*' group-name ''

# show sections in manuals
zstyle ':completion:*:manuals' separate-sections 'yes'

# describe options
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d' 

# ignore completion functions (until the _ignored completer)
zstyle ':completion:*:functions' ignored-patterns '_*'

# don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
#################################################

Offline

#13 2007-07-22 04:33:24

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Offline

#14 2007-07-22 06:43:33

faw
Member
Registered: 2007-06-09
Posts: 18

Re: Zsh(rc) Tips Thread

peets wrote:

zsh looks fun, but I feel comfortable with bash already. Try and sell me zsh. I read the website a bit and it looks great, but I'll need some convicning before I spend the effort of learning how to use it!

Well, I am not a salesperson by any means, and I definitely can't say that I am even close to being thoroughly familiar with either bash or zsh... smile

But I'm trying to learn a few things here and there, so I'm slowly going through this tutorial on the IBM website* and it (or the writer) seems to focus on zsh a bit: http://www.ibm.com/developerworks/aix/l … unix2.html

Seems like there is some value in giving zsh a go. I just came back to the archlinux forums and wiki to see if it's readily available and used much. Which it seems it is, so I guess I'll give it a go!

* I must admit that I like this IBM developerWorks site. I am not a 'developer' (or anything related to computers in professional sense), but it really does have a lot of introductory/transitionary documents for *nix that aren't too hard to understand. It's good. If only I could find the time to look some more..

Offline

#15 2007-07-25 03:14:56

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Zsh(rc) Tips Thread

Thanks faw. My problem is also with finding time for this. Having a comfortable shell that's really efficient must be very nice, but for now standard bash does the trick, for me.

Wow. I'll be spending some time there. Thanks codemac!

Last edited by peets (2007-07-25 03:18:41)

Offline

#16 2007-10-10 20:34:09

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: Zsh(rc) Tips Thread

I just started getting all of my configs organized and under version control.  I too am trying to make generic configs that will work across various operating systems, and have picked up a few ideas here.  This will definitely be changing, but if anyone cares to peruse my configs, they're posted here:

http://projects.elasticdog.com/hg/configs/

I'm also thinking about writing a quick script that will backup any old config files, then set up symlinks to the repository's versions so I can keep them all up to date easily.  I'll put that in the repo as well if anyone cares to adapt it for their own use.

Offline

#17 2007-10-11 04:00:40

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: Zsh(rc) Tips Thread

Holy crap ZSH is awesome...I've been reading/tweaking for a few hours and have come up with some really cool aliases.  I'll post the relevant stuff here, but my whole .zshrc can be found in the Mercurial repo above.

alias lsd='ls -d *(-/N)'      # list visible directories
alias lsf='ls *(-.N)'         # list visible files

alias la='ls -A'              # list all files/directories
alias lad='ls -d *(-/DN)'     # list all directories
alias laf='ls -A *(-.DN)'     # list all files
alias lla='ls -lhd *(-DN)'    # list details of all files/directories
alias llad='ls -lhd *(-/DN)'  # list details of all directories
alias llaf='ls -lhA *(-.DN)'  # list details of all files
alias ll='ls -lh'             # list details of visible files/directories
alias lld='ls -lhd *(-/N)'    # list details of visible directories
alias llf='ls -lh *(-.N)'     # list details of visible files
alias lh='ls -d .*'           # list hidden files/directories
alias lhd='ls -d .*(-/N)'     # list hidden directories
alias lhf='ls .*(-.N)'        # list hidden files
alias llh='ls -lhd .*'        # list details of hidden files/directories
alias llhd='ls -lhd .*(-/N)'  # list details of hidden directories
alias llhf='ls -lh .*(-.N)'   # list details of hidden files

alias le='ls -d *(-/DN^F)'         # list all empty directories
alias ler='ls -d **/*(-/DN^F)'     # list all empty directories recursively
alias lle='ls -ld *(-/DN^F)'       # list details of all empty directories
alias ller='ls -lhd **/*(-/DN^F)'  # list details of all empty directories recursively

# show sorted directory sizes for all directories
alias dua='du -s *(/DN) | sort -nr | cut -f 2- | while read a; do du -sh "$a"; done'

# show sorted directory sizes for visible directories only
alias duv='du -s *(/N) | sort -nr | cut -f 2- | while read a; do du -sh "$a"; done'

# show sorted directory sizes for hidden directories only
alias duh='du -s .*(/N) | sort -nr | cut -f 2- | while read a; do du -sh "$a"; done'

Last edited by elasticdog (2007-10-11 17:26:18)

Offline

#18 2007-10-11 07:18:39

F
Member
Registered: 2006-10-09
Posts: 322

Re: Zsh(rc) Tips Thread

Haha, hey elasticdog!

edit: cool site with zsh tips -- http://strcat.de/wiki/zsh

Last edited by F (2007-10-11 07:34:19)

Offline

#19 2007-10-11 17:24:06

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: Zsh(rc) Tips Thread

Lol...nice to see you again F :-)  I hadn't realized you were an Archer...thanks for the link, I'll check it out later this afternoone!

Offline

#20 2007-10-11 22:37:13

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: Zsh(rc) Tips Thread

20071011175203652x348scpn6.th.png

It's a slightly modified version of Phil!'s prompt.

Full rc:

# .zshrc
# ZShell configuration

# Xdefaults dont work well all the time
if [[ ! -f $HOME/.Xdefaults-$(uname -n) && -f $HOME/.Xdefaults ]] ; then
    ln -s $HOME/.Xdefaults $HOME/.Xdefaults-$(uname -n)
fi

# urxvt compensation
if [[ "${TERM}" == "rxvt-unicode" ]] ; then
    export TERM=rxvt
fi

# Which implementation in shell
function ewhich() {
    while [[ -n "$1" ]] ; do
    if type -p $1 &> /dev/null ; then
            echo $(type -p $1)
      else
            echo ""
    fi
    
    shift
   done
}

# Do we have which?
if ! type -p which &> /dev/null ; then alias which="ewhich" ; fi

# Override the default variables

if [ -d ~/bin ] ; then
    PATH=~/bin:"${PATH}"
fi

export HOSTNAME="$(uname -n)"
export HOSTTYPE="$(uname -m)"
export COLORTERM=yes
export CC=gcc
export PAGER=/usr/bin/less
export EDITOR="vim"

# UTF-8 Sexiness!! <cat call>
export LANG="en_US.utf8"
export LC_ALL="en_US.utf8"
export LC="en_US.utf8"
export LESSCHARSET="utf-8"

# GNU Colors
[ -f /etc/DIR_COLORS ] && eval $(dircolors -b /etc/DIR_COLORS)
export ZLSCOLORS="${LS_COLORS}"

# Alias commands
alias ls="ls -laph --color=auto"
alias mv="nocorrect mv"
alias cp="nocorrect cp"
alias man="nocorrect man"
alias mkdir="nocorrect mkdir"
alias mkcd="nocorrect mkcd"
alias rm="nocorrect rm"
alias ping="ping -c4"
alias df="df -h"
alias cgrep="grep --color=auto"
alias :q="exit"
alias :wq="exit"
alias y="yaourt"
alias nethack="telnet nethack.alt.org"

if type -p colorcvs &> /dev/null ; then alias cvs="colorcvs" ; fi
if type -p colordiff &> /dev/null ; then alias diff="colordiff" ; fi
if type -p colorgcc &> /dev/null ; then alias gcc="colorgcc" ; fi
if type -p colortail &> /dev/null ; then alias tail="colortail" ; fi
#if ! type -p ftp &> /dev/null ; then alias ftp="zftp" ; fi

# Bind keys
case $TERM in (xterm*) #Rutgers linux terminals
    bindkey "\eOH"  beginning-of-line
    bindkey "\eOF"  end-of-line
esac
bindkey '^E' end-of-line
bindkey '^A' beginning-of-line
bindkey "\e[2~" overwrite-mode
bindkey '^?' backward-delete-char
bindkey "\e[3~" delete-char
#bindkey "\e[5~" up-line-or-history
#bindkey "\e[6~" down-line-or-history
#bindkey "\e" vi-cmd-mode
#bindkey -A viins main
#set -o emacs

# Load Modules
autoload -U colors; colors
autoload -U compinit; compinit
autoload -U promptinit; promptinit

zmodload zsh/complist
zmodload zsh/termcap

#autoload -U zargs
#autoload -U zmv
#autoload -U zed
#autoload -U zcalc
#autoload -U zftp

if [[ ${ZSH_VERSION//\./} -ge 420 ]] ; then
    autoload -U url-quote-magic
    zle -N self-insert url-quote-magic
fi

# Disable core dumps
limit coredumpsize 0

# Configure ZSH History
setopt HIST_REDUCE_BLANKS
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
setopt BANG_HIST
HISTFILE=${HOME}/.zsh_history
SAVEHIST=1000
HISTSIZE=1600

# Terminal Options
setopt AUTO_CD           # implicate cd for non-commands
setopt CD_ABLE_VARS       # read vars in cd
setopt CORRECT            # correct spelling
setopt COMPLETE_IN_WORD       # complete commands anywhere in the word
setopt NOTIFY              # Notify when jobs finish
setopt C_BASES             # 0xFF
setopt BASH_AUTO_LIST      # Autolist options on repeition of ambiguous args
setopt CHASE_LINKS         # Follow links in cds
setopt AUTO_PUSHD          # Push dirs into history
setopt ALWAYS_TO_END       # Move to the end on complete completion
setopt LIST_ROWS_FIRST     # Row orientation for menu
setopt MULTIOS             # Allow Multiple pipes
setopt MAGIC_EQUAL_SUBST   # Expand inside equals
setopt EXTENDED_GLOB

# We are lazy -- look up spaces too
bindkey ' ' magic-space

# Menu!!
zstyle ':completion:*' menu select=1

# Colors on completion me-ow
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'

# Completion caching
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST

# Completion Options
zstyle ':completion:*:match:*' original only
zstyle ':completion::prefix-1:*' completer _complete
zstyle ':completion:predict:*' completer _complete
zstyle ':completion:incremental:*' completer _complete _correct
zstyle ':completion:*' completer _complete _prefix _correct _prefix _match _approximate

# Ignore completions for commands that we dont have
zstyle ':completion:*:functions' ignored-patterns '_*'

# Dont complete backups as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'

# Path Expansion
zstyle ':completion:*' expand 'yes'
zstyle ':completion:*' squeeze-shlashes 'yes'
zstyle ':completion::complete:*' '\\'

# Allow forced showing'
zstyle '*' single-ignored show

# Case insensitivity, partial matching, substitution
zstyle ':completion:*' matcher-list 'm:{A-Z}={a-z}' 'm:{a-z}={A-Z}' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'

# Group matches and Describe
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:descriptions' format $'\e[01;33m -- %d --\e[0m'
zstyle ':completion:*:messages' format $'\e[01;35m -- %d --\e[0m'
zstyle ':completion:*:warnings' format $'\e[01;31m -- No Matches Found --\e[0m'

# Prevent re-suggestion
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:scp:*' ignore-line yes
zstyle ':completion:*:ls:*' ignore-line yes

# Menu for KILL
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always

# Kill Menu Extension!
zstyle ':completion:*:processes' command 'ps -U $(whoami) | sed "/ps/d"'
zstyle ':completion:*:processes' insert-ids menu yes select 

# Remove uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
    adm alias apache at bin cron cyrus daemon ftp games gdm guest \
    haldaemon halt mail man messagebus mysql named news nobody nut \
    lp operator portage postfix postgres postmaster qmaild qmaill \
    qmailp qmailq qmailr qmails shutdown smmsp squid sshd sync \
    uucp vpopmail xfs

# Remove uninteresting hosts
zstyle ':completion:*:*:*:hosts-host' ignored-patterns \
    '*.*' loopback localhost
zstyle ':completion:*:*:*:hosts-domain' ignored-patterns \
    '<->.<->.<->.<->' '^*.*' '*@*'
zstyle ':completion:*:*:*:hosts-ipaddr' ignored-patterns \
    '^<->.<->.<->.<->' '127.0.0.<->'
zstyle -e ':completion:*:(ssh|scp):*' hosts 'reply=(
   ${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) \
   /dev/null)"}%%[# ]*}//,/ }
   )'

# SSH Completion
zstyle ':completion:*:scp:*' tag-order \
    files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:scp:*' group-order \
    files all-files users hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order \
    users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:ssh:*' group-order \
    hosts-domain hosts-host users hosts-ipaddr

# Make Completion
compile=(all clean compile disclean install remove uninstall)
compctl -k compile make

# Command File Type Detection
compctl -g '*.ebuild' ebuild
compctl -g '*.tex' + -g '*(-/)' latex
compctl -g '*.dvi' + -g '*(-/)' dvipdf dvipdfm
compctl -g '*.java' + -g '*(-/)' javac
compctl -g '*.tar.bz2 *.tar.gz *.bz2 *.gz *.jar *.rar *.tar *.tbz2 *.tgz *.zip *.Z' + -g '*(-/)' extract
compctl -g '*.mp3 *.ogg *.mod *.wav *.avi *.mpg *.mpeg *.wmv' + -g '*(-/)' mplayer
compctl -g '*.py' python
compctl -g '*(-/D)' cd
compctl -g '*(-/)' mkdir

# Command Parameter Completion
compctl -z fg
compctl -j kill
compctl -j disown
compctl -u chown
compctl -u su
compctl -c sudo
compctl -c which
compctl -c type
compctl -c hash
compctl -c unhash
compctl -o setopt
compctl -o unsetopt
compctl -a alias
compctl -a unalias
compctl -A shift
compctl -v export
compctl -v unset
compctl -v echo
compctl -b bindkey

# Handle logouts
trap exit_handler 0

function exit_handler() {
   # If we have a symlink to Xdefaults .. destroy it
    if [[ -h $HOME/.Xdefaults-$(uname -n) ]] ; then
    rm -f "$HOME/.Xdefaults-$(uname -n)"
    fi
    
    clear
}

# Welcome message for login shells
if [[ $SHLVL -eq 3 ]] ; then
    echo
    print -P "\e[1;32m Welcome to: \e[1;34m%m"
    print -P "\e[1;32m Running: \e[1;34m`uname -srm`\e[1;32m on \e[1;34m%l"
    print -P "\e[1;32m It is:\e[1;34m %D{%r} \e[1;32m on \e[1;34m%D{%A %b %f %G}"
    echo
fi

# Custom commands
glob_scp() {
    emulate -L zsh
    local -a args
    local a
    for a
    do
    if [[ $a = *:* ]]
    then
            args+=($a)# args+=($a) if you have zsh 4.2+
    else
            args+=($~a)# args+=($~a)
    fi
    done
    scp $args
}
alias scp='noglob glob_scp'

extract() {
   if [[ -z "$1" ]] ; then
       print -P "usage: \e[1;36mextract\e[1;0m < filename >"
       print -P "       Extract the file specified based on the extension"
   elif [[ -f $1 ]] ; then
       case ${(L)1} in
           *.tar.bz2)  tar -jxvf $1    ;;
           *.tar.gz)   tar -zxvf $1    ;;
           *.bz2)      bunzip2 $1       ;;
           *.gz)       gunzip $1       ;;
           *.jar)      unzip $1       ;;
           *.rar)      unrar x $1       ;;
           *.tar)      tar -xvf $1       ;;
           *.tbz2)     tar -jxvf $1    ;;
           *.tgz)      tar -zxvf $1    ;;
           *.zip)      unzip $1          ;;
           *.Z)        uncompress $1    ;;
           *)          echo "Unable to extract '$1' :: Unknown extension"
       esac
   else
       echo "File ('$1') does not exist!"
   fi
}

basiccalc() {
    if [[ ! -f /usr/bin/bc ]] ; then
    echo "Please install bc before trying to use it!"
    return
    fi
    
   if [[ -z "$1" ]] ; then
       /usr/bin/bc -q
   else
       echo "$@" | /usr/bin/bc -l
   fi
}

alias bc=basiccalc

echon() {
   # Convert to normal 0th element access
    local loc=$1
    shift
    
    echo $@[(w)$loc]
}

mkcd() {
    if [[ -z "$1" ]] ; then
    echo "usage: \e[1;36mmkcd \e[1;0m< directory >"
    echo "       Creates the specified directory and then changes it to pwd"
    else
    if [[ ! -d $1 ]] ; then
            mkdir -p $1 && cd $1
    else
            cd $1
    fi
    fi
}

unkey_host() {
    if [[ -z "$1" ]] ; then
    echo "usage: \e[1;36munkey_host \e[1;0m< host >"
    echo "       Removes the specified host from ssh known host list"
    else
    sed -i -e "/$1/d" $HOME/.ssh/known_hosts
   fi
}


function precmd {
    
    local TERMWIDTH
    (( TERMWIDTH = ${COLUMNS} - 1 ))

    
    ###
    # Truncate the path if it's too long.
    
    PR_FILLBAR=""
    PR_PWDLEN=""
    
    local promptsize=${#${(%):---(%n@%m:%l)---()--}}
    local pwdsize=${#${(%):-%~}}
    
    if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
    ((PR_PWDLEN=$TERMWIDTH - $promptsize))
    else
    PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
    fi
    
    
    ###
    # Get APM info.
    
    #if which ibam > /dev/null; then
    #PR_APM_RESULT=`ibam --percentbattery`
    #elif which apm > /dev/null; then
    #PR_APM_RESULT=`apm`
    #fi
}


setopt extended_glob
preexec () {
    if [[ "$TERM" == "screen" ]]; then
    local CMD=${1[(wr)^(*=*|sudo|-*)]}
    echo -n "\ek$CMD\e\\"
    fi
}


setprompt () {
    ###
    # Need this so the prompt will work.

    setopt prompt_subst
    

    ###
    # See if we can use colors.

    autoload colors zsh/terminfo
    if [[ "$terminfo[colors]" -ge 8 ]]; then
    colors
    fi
    for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
    eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
    eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
    (( count = $count + 1 ))
    done
    PR_NO_COLOUR="%{$terminfo[sgr0]%}"
    
    
    ###
    # See if we can use extended characters to look nicer.
    
    typeset -A altchar
    set -A altchar ${(s..)terminfo[acsc]}
    PR_SET_CHARSET="%{$terminfo[enacs]%}"
    PR_SHIFT_IN="%{$terminfo[smacs]%}"
    PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
    PR_HBAR=${altchar[q]:--}
    PR_ULCORNER=${altchar[l]:--}
    PR_LLCORNER=${altchar[m]:--}
    PR_LRCORNER=${altchar[j]:--}
    PR_URCORNER=${altchar[k]:--}
    
    
    ###
    # Decide if we need to set titlebar text.
    
    case $TERM in
    xterm*)
        PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
        ;;
    screen)
        PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
        ;;
    *)
        PR_TITLEBAR=''
        ;;
    esac
    
    
    ###
    # Decide whether to set a screen title
    if [[ "$TERM" == "screen" ]]; then
    PR_STITLE=$'%{\ekzsh\e\\%}'
    else
    PR_STITLE=''
    fi
    
    
    ###
    # APM detection
    
    #if which ibam > /dev/null; then
    #PR_APM='$PR_RED${${PR_APM_RESULT[(f)1]}[(w)-2]}%%(${${PR_APM_RESULT[(f)3]}[(w)-1]})$PR_LIGHT_BLUE:'
    #elif which apm > /dev/null; then
    #PR_APM='$PR_RED${PR_APM_RESULT[(w)5,(w)6]/\% /%%}$PR_LIGHT_BLUE:'
    #else
    PR_APM=''
    #fi
    
    
    ###
    # Finally, the prompt.
    
    PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
$PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@%m:%l\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_MAGENTA%$PR_PWDLEN<...<%~%<<\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\

$PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
${(e)PR_APM}$PR_YELLOW%D{%H:%M}\
$PR_LIGHT_BLUE:%(!.$PR_RED.$PR_WHITE)%#$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_NO_COLOUR '
    
    RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR'
    
    PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
}

setprompt

Last edited by buttons (2007-10-11 22:43:30)


Cthulhu For President!

Offline

#21 2008-01-13 12:42:56

Don-DiZzLe
Member
From: Nederland
Registered: 2007-03-31
Posts: 233

Re: Zsh(rc) Tips Thread

I've copied u'r .zshrc buttons, but I don't have those first 3 lines that u c in the screenie.
And what does the :% mean after the time?

Offline

#22 2008-01-13 13:02:17

Pierre
Developer
From: Bonn
Registered: 2004-07-05
Posts: 1,964
Website

Re: Zsh(rc) Tips Thread

Another nice source is http://www.grml.org/zsh/. My config is based on the grml-setup (I really like menu based completition): http://users.archlinux.de/~pierre/arch/zshrc

Offline

#23 2009-09-06 22:48:44

YamiFrankc
Member
From: Mexico
Registered: 2009-06-19
Posts: 177
Website

Re: Zsh(rc) Tips Thread

Hey Buttons.
Can you show us the code to have the prompt like that(just the prompt)?

┌─(yamifrankc@yami-laptop:pts/0)────────────────────────────────────────────────────────────────────(~)─┐
└─(17:47:%)──

Is very awesome.<3


Thanks and greetings.

Offline

#24 2009-09-14 12:56:10

csstaub
Member
From: Switzerland
Registered: 2009-02-09
Posts: 37

Re: Zsh(rc) Tips Thread

Here's mine.

## ZSHRC
## 2009-06-26

##
## The Basics
##

# Get global profile
source /etc/profile

# Bind keys
bindkey -e
bindkey '^P' push-line
bindkey '\e[7~' beginning-of-line
bindkey '\e[8~' end-of-line
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
bindkey '\e[3~' delete-char
bindkey "\e[2~" overwrite-mode
bindkey "^[OF" end-of-line
bindkey "^[OH" beginning-of-line
bindkey '^[Oc' emacs-forward-word
bindkey '^[Od' emacs-backward-word

# We want xterm to behave nicely
case $TERM in 
    (xterm*)
        bindkey '\e[H' beginning-of-line
        bindkey '\e[F' end-of-line ;;
esac

# Load colors for prompt
if autoload colors && colors 2>/dev/null; then
    # Zsh-style :-)
    BLUE="%{${fg[blue]}%}"
    BBLUE="%{${fg_bold[blue]}%}"
    RED="%{${fg[red]}%}"
    BRED="%{${fg_bold[red]}%}"
    GREEN="%{${fg[green]}%}"
    BGREEN="%{${fg_bold[green]}%}"
    CYAN="%{${fg[cyan]}%}"
    MAGENTA="%{${fg[magenta]}%}"
    YELLOW="%{${fg[yellow]}%}"
    WHITE="%{${fg[white]}%}"
    NO_COLOUR="%{${reset_color}%}"
else
    # Compatibility-style
    BLUE=$'%{\e[0;34m%}'
    BBLUE=$'%{\e[1;34m%}'
    RED=$'%{\e[0;31m%}'
    BRED=$'%{\e[1;31m%}'
    GREEN=$'%{\e[0;32m%}'
    BGREEN=$'%{\e[1;32m%}'
    CYAN=$'%{\e[1;36m%}'
    WHITE=$'%{\e[1;37m%}'
    MAGENTA=$'%{\e[1;35m%}'
    YELLOW=$'%{\e[1;33m%}'
    NO_COLOUR=$'%{\e[0m%}'
fi

# Load compinit for tab completion
autoload -U compinit && compinit

# Setup colors for ls/grep
eval $(dircolors -b)

##
## Environment variables
##

# Language, etc
export LANG="en_GB.utf8"
export LC_ALL="en_GB.utf8"
export LOCALE="en_GB.utf8"
export LC_PAPER="en_GB.utf8"
export ZLS_COLORS="$LS_COLORS"
export EDITOR="/usr/bin/nano -wOSAx"
export PATH=$PATH:/usr/local/bin
export HISTFILE=~/.zshhistory
export HISTSIZE=5000
export SAVEHIST=5000
export LISTMAX=0

# Null function
function null {
    $* >/dev/null 2>&1
}

# Command line prompt
if [ "$(whoami)" = "root" ]; then
    export PROMPT="${BRED}%m ${BBLUE}%1~ ${NO_COLOUR}${BLUE}#${NO_COLOUR} "
else
    export PROMPT="${BGREEN}%m ${BBLUE}%1~ ${NO_COLOUR}${BLUE}\$${NO_COLOUR} "
fi

# Aliases
alias gdb="gdb -q"
alias nano="nano -wOSAx"
alias l="ls -h --color=auto"
alias ls="ls -h --color=auto"
alias ll="ls -lh --color=auto"
alias la="ls -Ah --color=auto"
alias grep="grep --color=auto"
alias recall="history -5000 | grep"
alias mv='nocorrect mv'
alias cp='nocorrect cp'
alias mkdir='nocorrect mkdir'
alias zmodload='nocorrect zmodload'
alias ssh='nocorrect ssh' 
alias scp='nocorrect scp'
alias pacman='nocorrect pacman'

##
## Advanced functions
##

# Show current directory in title of urxvt/xterm
case $TERM in
    rxvt-*|xterm)
        print -Pn "\e]2;%m: %/\a"
        chpwd() { print -Pn "\e]2;%m: %/\a" }
    ;;
esac

# Show information about git repo on right-side prompt
git_info() {
    # Are we inside a git repo?
    if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
        # Get base directory
        gitbase=$(basename "$(dirname "$PWD/$(git rev-parse --git-dir)")")
        if [ "$gitbase" = "" ]; then return; fi

        # Get branch
        gitbranch=$(git branch --no-color | grep "^*" | cut -d' ' -f2-)
        if [ "$gitbranch" = "" ]; then return; fi

        # Get description
        gitdesc=$(git describe --tags 2>/dev/null)
        if [ "$gitdesc" = "" ]; then return; fi

        # Get status
        if ! git status | grep "working directory clean" >/dev/null 2>&1; then
            gitdesc="$gitdesc-dirty"
        fi

        RPROMPT="${MAGENTA}($gitbase:$gitbranch:$gitdesc)${NO_COLOUR}"
    fi
}       

# Enable precmd functions
precmd() {
    RPROMPT=""
    git_info
    export RPROMPT
}

##
## Zsh features
##

# Expansion options
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
zstyle ':completion:*:match:*' original only
zstyle ':completion::prefix-1:*' completer _complete
zstyle ':completion:incremental:*' completer _complete _correct
zstyle ':completion:predict:*' completer _complete
zstyle ':completion:*:functions' ignored-patterns '_*'

# Ignore backup files in complection (except for rm)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' '*?.*~' '*?.old' '*?.pro'

# Enable SSH completion
zstyle ':completion:*:scp:*' tag-order files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:scp:*' group-order files all-files users hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
zstyle '*' single-ignored show

# Complete manpages by section
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true

# Settings for URL matching
zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'

# Completion caching ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST

# Expand partial paths
zstyle ':completion:*' expand 'yes'
zstyle ':completion:*' squeeze-slashes 'yes'

# Include non-hidden directories in globbed file completions
zstyle ':completion::complete:*' '\'

# Tag-order 'globbed-files directories' all-files
zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'

# Don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'

# Separate matches into groups
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*' group-name ''

# Message formatting
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'

# Describe options in full
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'

# Set colors
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

# Zsh options
setopt                       \
     NO_all_export           \
        always_last_prompt   \
     NO_always_to_end        \
        append_history       \
     NO_auto_cd              \
        auto_list            \
        auto_menu            \
     NO_auto_name_dirs       \
        auto_param_keys      \
        auto_param_slash     \
        auto_pushd           \
        auto_remove_slash    \
     NO_auto_resume          \
     NO_bad_pattern          \
        bang_hist            \
     NO_beep                 \
        brace_ccl            \
     NO_bsd_echo             \
        cdable_vars          \
     NO_chase_links          \
     NO_clobber              \
        complete_aliases     \
        complete_in_word     \
        correct              \
     NO_correct_all          \
     NO_csh_junkie_history   \
     NO_csh_junkie_loops     \
     NO_csh_junkie_quotes    \
     NO_csh_null_glob        \
        equals               \
        extended_glob        \
        extended_history     \
        function_argzero     \
        glob                 \
     NO_glob_assign          \
        glob_complete        \
     NO_glob_dots            \
        glob_subst           \
        hash_cmds            \
        hash_dirs            \
        hash_list_all        \
        hist_allow_clobber   \
        hist_beep            \
        hist_ignore_dups     \
        hist_ignore_space    \
     NO_hist_no_store        \
        hist_verify          \
     NO_hup                  \
     NO_ignore_braces        \
     NO_ignore_eof           \
        interactive_comments \
        inc_append_history   \
     NO_list_ambiguous       \
     NO_list_beep            \
        list_types           \
        long_list_jobs       \
        magic_equal_subst    \
     NO_mail_warning         \
     NO_mark_dirs            \
     NO_menu_complete        \
        multios              \
     NO_nomatch              \
        notify               \
     NO_null_glob            \
        numeric_glob_sort    \
     NO_overstrike           \
        path_dirs            \
        posix_builtins       \
     NO_print_exit_value     \
     NO_prompt_cr            \
        prompt_subst         \
        pushd_ignore_dups    \
     NO_pushd_minus          \
        pushd_silent         \
        pushd_to_home        \
        rc_expand_param      \
     NO_rc_quotes            \
     NO_rm_star_silent       \
     NO_sh_file_expansion    \
        sh_option_letters    \
        short_loops          \
     NO_sh_word_split        \
     NO_single_line_zle      \
     NO_sun_keyboard_hack    \
        unset                \
     NO_verbose              \
        zle

Offline

#25 2009-09-14 15:15:19

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: Zsh(rc) Tips Thread

YamiFrankc wrote:

Hey Buttons.
Can you show us the code to have the prompt like that(just the prompt)?

┌─(yamifrankc@yami-laptop:pts/0)────────────────────────────────────────────────────────────────────(~)─┐
└─(17:47:%)──

Is very awesome.<3

Yep

function precmd {
    
    local TERMWIDTH
    (( TERMWIDTH = ${COLUMNS} - 1 ))

    
    ###
    # Truncate the path if it's too long.
    
    PR_FILLBAR=""
    PR_PWDLEN=""
    
    local promptsize=${#${(%):---(%n@%m:%l)---()--}}
    local pwdsize=${#${(%):-%~}}
    
    if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
    ((PR_PWDLEN=$TERMWIDTH - $promptsize))
    else
    PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
    fi
    
    
    ###
    # Get APM info.
    
    #if which ibam > /dev/null; then
    #PR_APM_RESULT=`ibam --percentbattery`
    #elif which apm > /dev/null; then
    #PR_APM_RESULT=`apm`
    #fi
}


setopt extended_glob
preexec () {
    if [[ "$TERM" == "screen" ]]; then
    local CMD=${1[(wr)^(*=*|sudo|-*)]}
    echo -n "\ek$CMD\e\\"
    fi
}


setprompt () {
    ###
    # Need this so the prompt will work.

    setopt prompt_subst
    

    ###
    # See if we can use colors.

    autoload colors zsh/terminfo
    if [[ "$terminfo[colors]" -ge 8 ]]; then
    colors
    fi
    for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
    eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
    eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
    (( count = $count + 1 ))
    done
    PR_NO_COLOUR="%{$terminfo[sgr0]%}"
    
    
    ###
    # See if we can use extended characters to look nicer.
    
    typeset -A altchar
    set -A altchar ${(s..)terminfo[acsc]}
    PR_SET_CHARSET="%{$terminfo[enacs]%}"
    PR_SHIFT_IN="%{$terminfo[smacs]%}"
    PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
    PR_HBAR=${altchar[q]:--}
    #PR_HBAR=" "
    PR_ULCORNER=${altchar[l]:--}
    PR_LLCORNER=${altchar[m]:--}
    PR_LRCORNER=${altchar[j]:--}
    PR_URCORNER=${altchar[k]:--}
    
    
    ###
    # Decide if we need to set titlebar text.
    
    case $TERM in
    xterm*)
        PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
        ;;
    screen)
        PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
        ;;
    *)
        PR_TITLEBAR=''
        ;;
    esac
    
    
    ###
    # Decide whether to set a screen title
    if [[ "$TERM" == "screen" ]]; then
    PR_STITLE=$'%{\ekzsh\e\\%}'
    else
    PR_STITLE=''
    fi
    
    
    ###
    # APM detection
    
    #if which ibam > /dev/null; then
    #PR_APM='$PR_RED${${PR_APM_RESULT[(f)1]}[(w)-2]}%%(${${PR_APM_RESULT[(f)3]}[(w)-1]})$PR_LIGHT_BLUE:'
    #elif which apm > /dev/null; then
    #PR_APM='$PR_RED${PR_APM_RESULT[(w)5,(w)6]/\% /%%}$PR_LIGHT_BLUE:'
    #else
    PR_APM=''
    #fi
    
    
    ###
    # Finally, the prompt.
    
    PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
$PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@%m:%l\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_MAGENTA%$PR_PWDLEN<...<%~%<<\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\

$PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
${(e)PR_APM}$PR_YELLOW%D{%H:%M}\
$PR_LIGHT_BLUE:%(!.$PR_RED.$PR_WHITE)%#$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_NO_COLOUR '
    
    RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR'
    
    PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
}

setprompt

I *think* that's everything...


Cthulhu For President!

Offline

Board footer

Powered by FluxBB