Skip to content

anonymous /gist:4047751
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/bin/zsh
# Set up the prompt
setopt histignorealldups sharehistory
# assume "cd" when a command is a directory
setopt autocd
# Prompt style
if [ $EUID -lt 1000 ]; then
PS1="%F{yellow}[%*] %(!.%F{red}.%F{magenta})%n@%M%k %B%F{green}%(8~|...|)%7~%F{white} %# %b%f%k"
else
PS1="%F{yellow}[%*] %(!.%F{red}.%F{cyan})%n@%M%k %B%F{green}%(8~|...|)%7~%F{white} %# %b%f%k"
fi
# Keep 1000 lines of history within the shell and save it to ~/.cache/shell_history
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.cache/shell_history
# Use modern completion system
autoload -Uz compinit
compinit
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
# keybinds
# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e
typeset -A key
key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
key[Insert]=${terminfo[kich1]}
key[Delete]=${terminfo[kdch1]}
key[Up]=${terminfo[kcuu1]}
key[Down]=${terminfo[kcud1]}
key[Left]=${terminfo[kcub1]}
key[Right]=${terminfo[kcuf1]}
key[PageUp]=${terminfo[kpp]}
key[PageDown]=${terminfo[knp]}
# setup key accordingly
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
# Make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init () {
printf '%s' ${terminfo[smkx]}
}
function zle-line-finish () {
printf '%s' ${terminfo[rmkx]}
}
zle -N zle-line-init
zle -N zle-line-finish
fi
# Bind ctrl-left / ctrl-right
bindkey "\e[1;5D" backward-word
bindkey "\e[1;5C" forward-word
# Bind ctrl-backspace to delete word. NOTE: This may not work properly in some emulators
# bindkey "^?" backward-delete-word
# Bind shift-tab to backwards-menu
# NOTE this won't work on Konsole if the new tab button is shown
bindkey "\e[Z" reverse-menu-complete
# Aliases
# Colors
alias ls='ls -F --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'
alias less='less -R' # make less accept color codes and re-output them
# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias lh='ls -lh'
alias l='ls -CF'
alias lash='ls -lAsh'
alias sl='ls'
# developer aliases
# Alias make to a proper amount of cores
alias make="make -j$(grep processor /proc/cpuinfo | wc -l)"
# From grml's zshrc!
# https://github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc
# make a backup of a file
bk() {
cp -a "$1" "${1}_$(date --iso-8601=seconds)"
}
# Create small urls via http://goo.gl using curl(1).
# API reference: https://code.google.com/apis/urlshortener/
function zurl() {
emulate -L zsh
if [[ -z $1 ]]; then
print "USAGE: zurl <URL>"
return 1
fi
local PN url prog api json data
PN=$0
url=$1
# Prepend 'http://' to given URL where necessary for later output.
if [[ ${url} != http(s|)://* ]]; then
url='http://'${url}
fi
prog=curl
api='https://www.googleapis.com/urlshortener/v1/url'
contenttype="Content-Type: application/json"
json="{\"longUrl\": \"${url}\"}"
data=$($prog --silent -H ${contenttype} -d ${json} $api)
# Match against a regex and print it
if [[ $data =~ '"id": "(http://goo.gl/[[:alnum:]]+)"' ]]; then
print $match
fi
}
# simple webserver
alias http="python -mhttp.server"
# json prettify
alias json="python -mjson.tool"
# display octal permission of file
alias om="stat --printf='%a %n\n'"
alias myip="curl ifconfig.me"
function htmime() {
if [[ -z $1 ]]; then
print "USAGE: htmime <URL>"
return 1
fi
mime=$(curl -sI $1 | grep ^Content-Type | sed "s/Content-Type: //")
print $mime
}
function urlencode {
setopt extendedglob
echo "${${(j: :)@}//(#b)(?)/%$[[##16]##${match[1]}]}"
}
function google {
xdg-open "http://www.google.com/search?q=`urlencode "${(j: :)@}"`"
}
# xdg basedir-related stuff
alias skype="skype --dbpath=$HOME/.config/skype"
alias nvidia-settings="nvidia-settings --config=$HOME/.config/nvidia-settings"
export CCACHE_DIR="$HOME/.cache/ccache"
export MPLAYER_HOME=$HOME/.config/mplayer
export WORKON_HOME=$HOME/.local/share/virtualenvs
export PATH=$HOME/bin:$PATH
# virtualenvwrapper
export WORKON_HOME=$XDG_DATA_HOME/virtualenvs
export PROJECT_HOME=$HOME/src/git
source virtualenvwrapper_lazy.sh
# Arch linux uses python3 by default, this is required to make python2-compatible projects
alias mkproject2="mkproject -p python2"
alias mkvirtualenv2="mkvirtualenv -p python2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.