SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2009-08-12 17:28:15

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,486

zsh is awesome

just wanted to let everyone know, I've been playing around with it lately. I love it big_smile If anyone has some good zsh hints for me post them here please since I'm just starting.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

Be excellent to each other!

#2 2009-08-12 22:32:49

fhsm
#! Junkie
From: New Hampshire, USA
Registered: 2009-01-05
Posts: 445

Re: zsh is awesome

I'm a huge ZSH fan.  Maybe we could work on a .zshrc thread...

I'll clean mine up as soon as I get a chance.

Offline

#3 2009-08-13 05:39:49

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,486

Re: zsh is awesome

Thanks big_smile I just used the autoconfigure thing to setup up my initial .zshrc . I need to start digging into it to customize now.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#4 2009-08-13 22:00:43

fhsm
#! Junkie
From: New Hampshire, USA
Registered: 2009-01-05
Posts: 445

Re: zsh is awesome

Okay so my setup is to have ~/.zsh/ with the following:

dot-zshrc
zsh_history
functions/
  prompt_fhsm_setup

and then symlink ~/.zshrc to ~/.zsh/dot-zshrc (obviously the whole symlink dot-zshrc is optional but I like it to keep my backups cleaner).

~/.zsh/functions/prompt_fhsm_setup is the following:

# fhsm prompt theme

prompt_fhsm_help () {
  cat <<'EOF'
This prompt is color-scheme-able.  You can invoke it with:

  prompt fhsm [ 8bit ] [<color1> [<color2> [<color3>] [<color4>] [<color5>]]

where the colors are for the hyphens, current directory, user,
host and user input respectively.  The default colors are cyan, green,
magenta, blue and white.  This theme requires a dark background.

If you have either UTF-8 or the `nexus' or `vga' console fonts or similar,
you can specify the `8bit' option to use 8-bit replacements for the
7-bit characters.

This is a rip off of the adam2 theme.

EOF
}

prompt_fhsm_setup () {
  # Some can't be local
  local prompt_gfx_tlc prompt_gfx_mlc prompt_gfx_blc

  if [[ $1 == '8bit' ]]; then
    shift
    if [[ ${LC_ALL:-${LC_CTYPE:-$LANG}} = *UTF-8* ]]; then
      prompt_gfx_tlc=$'\xe2\x94\x8c'
      prompt_gfx_mlc=$'\xe2\x94\x9c'
      prompt_gfx_blc=$'\xe2\x94\x94'
      prompt_gfx_hyphen=$'\xe2\x94\x80'
    else
      prompt_gfx_tlc=$'\xda'
      prompt_gfx_mlc=$'\xc3'
      prompt_gfx_blc=$'\xc0'
      prompt_gfx_hyphen=$'\xc4'
    fi
  else
    prompt_gfx_tlc='.'
    prompt_gfx_mlc='|'
    prompt_gfx_blc='\`'
    prompt_gfx_hyphen='-'
  fi

  # Default color scheme
  prompt_fhsm_color1=${1:-'cyan'}    # hyphens
  prompt_fhsm_color2=${2:-'green'}   # current directory
  prompt_fhsm_color3=${3:-'magenta'} # user@
  prompt_fhsm_color4=${4:-'blue'}    # host
  prompt_fhsm_color5=${5:-'white'}   # user input

  local prompt_gfx_bbox 
  prompt_gfx_tbox="%{$fg_bold[$prompt_fhsm_color1]%}${prompt_gfx_tlc}%{$fg_no_bold[$prompt_fhsm_color1]%}${prompt_gfx_hyphen}"
  prompt_gfx_bbox="%{$fg_bold[$prompt_fhsm_color1]%}${prompt_gfx_blc}${prompt_gfx_hyphen}%{$fg_no_bold[$prompt_fhsm_color1]%}"

  # This is a cute hack.  Well I like it, anyway.
  prompt_gfx_bbox_to_mbox=$'%{\e[A\r'"$fg_bold[$prompt_fhsm_color1]${prompt_gfx_mlc}$fg_no_bold[$prompt_fhsm_color1]${prompt_gfx_hyphen}"$'\e[B%}'

  prompt_l_paren="%{$fg_bold[grey]%}("
  prompt_r_paren="%{$fg_bold[grey]%})"

  prompt_user_host="%{$fg_bold[$prompt_fhsm_color4]%}%n%{$fg_no_bold[$prompt_fhsm_color4]%}@%{$fg_no_bold[$prompt_fhsm_color3]%}%m"

  prompt_line_1a="$prompt_gfx_tbox$prompt_l_paren%{$fg_bold[$prompt_fhsm_color2]%}%~$prompt_r_paren%{$fg_no_bold[$prompt_fhsm_color1]%}"
  prompt_line_1b="$prompt_l_paren$prompt_user_host$prompt_r_paren%{$fg_no_bold[$prompt_fhsm_color1]%}${prompt_gfx_hyphen}"

  prompt_line_2="$prompt_gfx_bbox${prompt_gfx_hyphen}%{$fg_bold[white]%}"

  prompt_char="%(!.#.>)"

  precmd () { prompt_fhsm_precmd; setopt promptsubst }
  preexec () { prompt_fhsm_preexec }
}

prompt_fhsm_precmd () {
  setopt noxtrace localoptions extendedglob
  local prompt_line_1

  prompt_fhsm_choose_prompt

  PS1="$prompt_line_1$prompt_newline$prompt_line_2%{$fg_bold[white]%}$prompt_char %{$fg_bold[$prompt_fhsm_color5]%}"
  PS2="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold[white]%}%_> %{$fg_bold[$prompt_fhsm_color5]%}"
  PS3="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold[white]%}?# %{$fg_bold[$prompt_fhsm_color5]%}"
  RPS1=$'%{\e[1;30m%}<%T%{\e[0m%}%(?..%{\e[0;31m%} %?%{\e[0m%})' 
      #this is a bit unclear but the %{ %} is tells zsh not to count those chars into the prompt length, ie escape seq.
      #then the \e[...m part is a color seqence, \e[0m is the color reset seqence
      #%T is just expanded to the time
      #Next is a test for the exit code of the previous command using %?
      #This test uses the %([char].[true str].[false str]) construct to test for non zero exit codes
      #Zero exit codes print nothing because the true str is blank, the .., but the false string prints the exit code in red
}

prompt_fhsm_choose_prompt () {
  local prompt_line_1a_width=${#${(S%%)prompt_line_1a//\%\{*\%\}}}
  local prompt_line_1b_width=${#${(S%%)prompt_line_1b//\%\{*\%\}}}

  local prompt_padding_size=$(( COLUMNS
                                  - prompt_line_1a_width
                                  - prompt_line_1b_width ))

  # Try to fit in long path and user@host.
  if (( prompt_padding_size > 0 )); then
    local prompt_padding
    eval "prompt_padding=\${(l:${prompt_padding_size}::${prompt_gfx_hyphen}:)_empty_zz}"
    prompt_line_1="$prompt_line_1a$prompt_padding$prompt_line_1b"
    return
  fi

  prompt_padding_size=$(( COLUMNS - prompt_line_1a_width ))

  # Didn't fit; try to fit in just long path.
  if (( prompt_padding_size > 0 )); then
    local prompt_padding
    eval "prompt_padding=\${(l:${prompt_padding_size}::${prompt_gfx_hyphen}:)_empty_zz}"
    prompt_line_1="$prompt_line_1a$prompt_padding"
    return
  fi

  # Still didn't fit; truncate 
  local prompt_pwd_size=$(( COLUMNS - 5 ))
  prompt_line_1="$prompt_gfx_tbox$prompt_l_paren%{$fg_bold[$prompt_fhsm_color2]%}%$prompt_pwd_size<...<%~%<<$prompt_r_paren%{$fg_no_bold[$prompt_fhsm_color1]$prompt_gfx_hyphen%}"
}

prompt_fhsm_preexec () {
  print -n "$reset_color"
}

prompt_fhsm_setup "$@"

~/.zsh/dot-zshrc contains the following:

case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

#------------------------------------------////
# Basic Configuration:
#------------------------------------------////
#kill the beep alarm
setopt no_beep

#Make a history file
export HISTSIZE=2000
export HISTFILE="$HOME/.zsh/zsh_history"
export SAVEHIST=$HISTSIZE #this line is required to save the file

#enable auto-correct
setopt correctall

#turn on tab completion and make it fancy
autoload -U compinit && compinit
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'

#fancy colors and prompts are set later
#add custom functions to path (important for prompt)
fpath=(~/.zsh/functions $fpath)

#remove right prompt after command is run (helpful if copying and pasting)
#setopt TRANSIENT_RPROMPT
#------------------------------------------////
# Colors:
#------------------------------------------////
black='\e[0;30m'
blue='\e[0;34m'
green='\e[0;32m'
cyan='\e[0;36m'
red='\e[0;31m'
purple='\e[0;35m'
brown='\e[0;33m'
lightgray='\e[0;37m'
darkgray='\e[1;30m'
lightblue='\e[1;34m'
lightgreen='\e[1;32m'
lightcyan='\e[1;36m'
lightred='\e[1;31m'
lightpurple='\e[1;35m'
yellow='\e[1;33m'
white='\e[1;37m'
nc='\e[0m'

#Colors for less pager (man pages)
export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
export LESS_TERMCAP_me=$'\E[0m'           # end mode
export LESS_TERMCAP_se=$'\E[0m'           # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m'    # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m'           # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline


# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    alias dir='dir --color=auto'
    alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

#------------------------------------------////
# Custom Prompt:
#------------------------------------------////
# Nice basic prompt
#export PS1="%n@%m:%~%# "
#export RPS1=" <%T"
#export PS2="%_> "

# Colorful basic prompt option 1
#autoload -U colors && colors
#export PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
#export RPS1="%{$fg[cyan]%}<%T%{$reset_color%}"
#export PS2="%_> "

# Colorful basic prompt option 2 { Better than option 1 }
#export PS1=$'%{\e[1;32m%}%n%{\e[0m%}%{\e[1;34m%}@%{\e[1;31m%}%m %{\e[1;34m%}%~ %{\e[0m%}%% '
#export RPS1=$'%{\e[1;30m%}<%T%{\e[0m%}'
#export PS2=$'%{\e[0;37m%} %_>%{\e[0m%} '

# Fancy prompt system see /usr/share/zsh/functions/Prompts/ for files
# the "fhsm" configuration is loaded from ~/.zsh/functions, which is added to the path above.
# List options with: prompt -l
autoload -U promptinit && promptinit 
prompt fhsm


#------------------------------------------////
# Aliases:
#------------------------------------------////
# Useful aliases (building on the color enablers)
alias ll='ls -l'
alias la='ls -Al'
alias lb='ls -Al --block-size=1MB'
alias reload='source ~/.zshrc'
alias biggest='BLOCKSIZE=1048576; du -x | sort -nr | head -10'

# Shortcuts
alias home='cd ~/'
alias documents='cd ~/documents'
alias downloads='cd ~/downloads'
alias images='cd ~/images'
alias videos='cd ~/videos'

## Sudo fixes
alias install='~/bin/install_and_log install'
alias remove='sudo apt-get remove'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get update && sudo apt-get upgrade'
alias dist-upgrade='sudo apt-get update && sudo apt-get dist-upgrade'
alias orphand='sudo deborphan | xargs sudo apt-get -y remove --purge'
alias cleanup='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean && sudo apt-get remove && orphand'
alias search="apt-cache search"


##Info
alias stamp='date "+%Y-%m-%d %a %H:%M"'
alias da='date "+%Y-%m-%d %A    %T %Z"'

#------------------------------------------////
# Custom Extract / Compress:
#------------------------------------------////
# Easy extract
extract () {
  if [ -f $1 ] ; then
      case $1 in
          *.tar.bz2)   tar xvjf $1    ;;
          *.tar.gz)    tar xvzf $1    ;;
          *.bz2)       bunzip2 $1     ;;
          *.rar)       rar x $1       ;;
          *.gz)        gunzip $1      ;;
          *.tar)       tar xvf $1     ;;
          *.tbz2)      tar xvjf $1    ;;
          *.tgz)       tar xvzf $1    ;;
          *.zip)       unzip $1       ;;
          *.Z)         uncompress $1  ;;
          *.7z)        7z x $1        ;;
          *)           echo "don't know how to extract '$1'..." ;;
      esac
  else
      echo "'$1' is not a valid file!"
  fi
}

# Creates an archive from given directory
mktar() { tar cvf  "${1%%/}.tar"     "${1%%/}/"; }
mktgz() { tar cvzf "${1%%/}.tar.gz"  "${1%%/}/"; }
mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; }


#------------------------------------------////
# Other Custom Functions:
#------------------------------------------////
# Get weather (replace the ##### in the url with your own zipcode, call it by typing weather)
weather ()
{ 
declare -a WEATHERARRAY 
WEATHERARRAY=( `elinks -dump "http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=weather+#####&btnG=Search" | grep -A 5 -m 1 "Weather for" | grep -v "Add to "`) 
echo ${WEATHERARRAY[@]}
}
upinfo ()
{
echo -ne "\t ";uptime | awk /'up/ {print $3,$4,$5,$6,$7,$8,$9,$10}'
}

#------------------------------------------////
# Custom Alias:
#------------------------------------------////

#Flash
alias flash_dump='rm -rf ~/.macromedia/Flash_Player/#SharedObjects/ZXAEK53N/* && rm -rf ~/.macromedia/Flash_Player/macromedia.com/support/flashplayer/sys/*'

#------------------------------------------////
# Welcome Info:
#------------------------------------------////
clear
echo -e "${LIGHTGRAY}";figlet " Z-Shell #!";
echo -ne "${red}Today is:\t\t${cyan}" `date`; echo ""
echo -e "${red}Kernel Information: \t${cyan}" `uname -smr`
echo -ne "${red}Uptime is: \t${cyan}";upinfo;echo ""

I realize this is a LOT of config and it may not be to your taste but It should at least give you an idea of what can be done w/ zsh.  I keep zsh bound to super+z and a nice simple bash bound to super+t, plus tilda running on F1.  I find I use bash in tilda about 40% of the time, zsh about 50% of the time and bash in terminator the rest of the time.

I've pulled all my custom alias junk so that this will be a cleaner starting point for you.  I did include a couple of extra prompts just so you could have some other material to work with. 

I look forward to seeing what you end up doing.

Offline

#5 2009-08-14 06:23:21

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,486

Re: zsh is awesome

Thanks I really appreciate it, I'll start digging through it tonight big_smile


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#6 2010-01-10 04:32:25

Digit
#! Die Hard
From: the internet
Registered: 2009-05-26
Posts: 1,050
Website

Re: zsh is awesome

i just did a quick search for zsh vs bash, n came across this, started reading... and now i think i have a new project for tomorrow morning.  big_smile


~ think ~
i have chosen to commit to bedrocklinux.
causes of the mo: remember aaron | stop lennart (& systemd) | without a shot fired

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo