public
anonymous / gist:4047751
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
#!/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"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.