Skip to content

Instantly share code, notes, and snippets.

@zemlanin
Created December 13, 2012 14:14
Show Gist options
  • Save zemlanin/4276628 to your computer and use it in GitHub Desktop.
Save zemlanin/4276628 to your computer and use it in GitHub Desktop.
.zshrc
update_current_vcs_vars
# cp loader.zshrc ~/.zshrc
source ~/.zsh/zshrc
export PUSHOVER_APP="your pushover.net app token"
export PUSHOVER_USER="your pushover.net user key"
export PUSHOVER_DEVICE="default device"
export YO_APP="your justyo.co app token"
# python quick calculation in zsh
# https://gist.github.com/zemlanin/5322437
# input:
# p 2+4 4.0/3 _0+_1
#
# and get output like:
# _0> 6
# _1> 1.3333333333333333
# _2> 7.333333333333333
__p(){
local args
local i
local index=0
for i in "$@"; do
args+="_$index=eval('$i'); print('\t_$index>', _$index);"
let "index+=1"
done
command python3 -c "$args"
}
alias p="noglob __p"
if [ -n "$__EXECUTED_VCS_COMMAND" ]; then
update_current_vcs_vars
unset __EXECUTED_VCS_COMMAND
fi
__EXECUTED_VCS_COMMAND=1
if [ -n "$__CURRENT_GIT_BRANCH" ]; then
local s=""
case "$__CURRENT_GIT_BRANCH_STATUS" in
ahead)
s="%{$fg_bold[blue]%}↑"
;;
diverged)
s="%{$fg_bold[yellow]%}↕"
;;
behind)
s="%{$fg_bold[green]%}↓"
;;
esac
if [ -n "$__CURRENT_GIT_BRANCH_IS_DIRTY" ]; then
s="%{$fg_bold[red]%}⚡"
fi
printf " %s%s%s 🍪 " $s "$__CURRENT_GIT_BRANCH" "%{$reset_color%}"
fi
if [ -n "$__CURRENT_HG_BRANCH" ]; then
printf " %s%s%s" "%{$fg_bold[blue]%}" $(
hg branches|grep -o '^1[0-9].[0-9][0-9].[0-9]'|sort -r|head -1
) "%{$reset_color%}"
local s=""
if [ -n "$__CURRENT_HG_BRANCH_IS_DIRTY" ]; then
s="%{$fg_bold[red]%}"
else
s="%{$fg_bold[green]%}"
fi
printf " %s%s%s 🍪 " $s "$__CURRENT_HG_BRANCH" "%{$reset_color%}"
fi
# emoji in ubuntu: https://gist.github.com/zemlanin/5321821
PROMPT='%{$bg[yellow]%}%{$fg_bold[white]%}%B%~%b%{$reset_color%} 🍔 '
PROMPT+='$(prompt_vcs_info)' # vcs info
PROMPT+='%(1j. %{$bg[white]%}%{$fg[gray]%}%j%{$reset_color%}.) ' # background jobs
# differentiate hostname by color
# https://gist.github.com/zemlanin/5325942
__colorcode=$(
(
echo "ibase=16"; hostname | md5sum | cut -c1-2 | tr "[:lower:]" "[:upper:]"
) | bc | awk '{printf "[48;5;%dm", $1}' # background
)
__colorcode+=$(
(
echo "ibase=16"; hostname | md5sum | cut -c3-4 | tr "[:lower:]" "[:upper:]"
) | bc | awk '{printf "[38;5;%dm", $1}' # foreground
)
RPROMPT='%{$__colorcode%}%n%{$reset_color%}'
# send message to your devices via pushover.net API
# add next two or three lines to .bashrc/.zshrc to use this script
# export PUSHOVER_APP="your pushover.net app token"
# export PUSHOVER_USER="your pushover.net user key"
# optional:
# export PUSHOVER_DEVICE="default device"
# USAGE: push <message> [-d=<device>]
# OPTIONS:
# -d Device name (send to $PUSHOVER_DEVICE if empty)
__pushover(){
local device=""
local message=$1
shift 1
while getopts ":d:" OPTION
do
case $OPTION in
d)
device=$OPTARG
;;
esac
done
if [[ -z $device ]]
then
device=$PUSHOVER_DEVICE
fi
if [[ -z $message ]]
then
echo 'message required'
else
command curl -s -F "token=$PUSHOVER_APP" \
-F "user=$PUSHOVER_USER" \
-F "message=$message" \
-F "device=$device" \
https://api.pushover.net/1/messages.json
fi
}
alias push=__pushover
unset __CURRENT_GIT_BRANCH
unset __CURRENT_GIT_BRANCH_STATUS
unset __CURRENT_GIT_BRANCH_IS_DIRTY
unset __CURRENT_HG_BRANCH
unset __CURRENT_HG_IS_TIP
unset __CURRENT_HG_BRANCH_IS_DIRTY
local st="$(git status 2>/dev/null)"
if [[ -n "$st" ]]; then
local -a arr
arr=(${(f)st})
if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
__CURRENT_GIT_BRANCH='no-branch'
else
__CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
fi
if [[ $arr[2] =~ 'Your branch is' ]]; then
if [[ $arr[2] =~ 'ahead' ]]; then
__CURRENT_GIT_BRANCH_STATUS='ahead'
elif [[ $arr[2] =~ 'diverged' ]]; then
__CURRENT_GIT_BRANCH_STATUS='diverged'
else
__CURRENT_GIT_BRANCH_STATUS='behind'
fi
fi
if [[ ! $st =~ 'nothing to commit' ]]; then
__CURRENT_GIT_BRANCH_IS_DIRTY='1'
fi
fi
local hg_br="$(hg id -nb 2>/dev/null)"
if [[ -n "$hg_br" ]]; then
__CURRENT_HG_BRANCH="$hg_br[(w)2]"
if [ "$hg_br[(w)1]" "!=" $(hg id --debug -i -r tip) ]; then
__CURRENT_HG_IS_TIP=1
fi
if [[ -n "$(hg status -q)" ]]; then
__CURRENT_HG_BRANCH_IS_DIRTY=1
fi
fi
# send yo to your devices via Yo API
# add next line to .bashrc/.zshrc to use this script
# export YO_APP="your justyo.co app token"
# USAGE: yop [link]
__yop(){
local link=$1
local api_url="http://api.justyo.co/yoall/"
command curl -s -F "api_token=$YO_APP" -F "link=$link" $api_url
}
alias yop=__yop
autoload -U colors && colors
autoload -U compinit
export TERM=screen-256color
export GREP_OPTIONS='--color=auto'
# imports
source ~/.zsh/p.sh
source ~/.zsh/yop.sh
source ~/.zsh/push.sh
source ~/.zsh/prompts.sh
###### colorful ls #######
if [[ -x "`whence -p dircolors`" ]]; then
eval `dircolors`
alias ls='ls -F --color=auto'
else
alias ls='ls -F'
fi
###### aliases etc. #######
cdpath=( . ~ )
export EDITOR='subl --wait'
export BROWSER=chromium-browser
# shortcuts
alias e=subl
alias k=tree
alias cr=$BROWSER
alias ci="$BROWSER --incognito"
alias runashell="sudo pkill -KILL -u"
alias runvnc="vncserver -depth 8 -geometry 1024x768 :5"
alias kilvnc="vncserver -kill :5"
alias p2="python2"
alias p3="python3"
alias git="LANG=en_GB git"
# wrong keyboard layout
alias ап=fg
alias св=cd
alias ды=ls
###### history ######
HISTSIZE=10240 # кол-во команд, хранимых шеллом в текущей сессии
setopt COMPLETE_ALIASES
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
#if [ $(hostname | cut -c1-1) "!=" "h" ]; then
HISTFILE=~/.history
SAVEHIST=8192 # кол-во команд, которые будут сохранены в истории
setopt SHARE_HISTORY
setopt HIST_NO_STORE
#fi
###### vcs #######
# Allow for functions in the prompt.
setopt PROMPT_SUBST
# Autoload zsh functions.
fpath=(~/.zsh/functions $fpath)
autoload -U ~/.zsh/functions/*(:t)
# Append vcs functions needed for prompt.
preexec_functions=($preexec_functions 'preexec_update_vcs_vars')
precmd_functions=($precmd_functions 'precmd_update_vcs_vars')
chpwd_functions=($chpwd_functions 'chpwd_update_vcs_vars')
# Enable auto-execution of functions.
$preexec_functions; $precmd_functions; $chpwd_functions
###### bindkeys ######
bindkey "\e[A" history-beginning-search-backward
bindkey "^[OA" history-beginning-search-backward
bindkey "\e[B" history-beginning-search-forward
bindkey "^[OB" history-beginning-search-forward
bindkey "\e[1~" beginning-of-line # Home
bindkey "\e[4~" end-of-line # End
bindkey "\e[5~" beginning-of-history # PageUp
bindkey "\e[6~" end-of-history # PageDown
bindkey "\e[2~" quoted-insert # Ins
bindkey "\e[3~" delete-char # Del
bindkey "\e[5C" forward-word
bindkey "\eOc" emacs-forward-word
bindkey "\e[5D" backward-word
bindkey "\eOd" emacs-backward-word
bindkey "\e\e[C" forward-word
bindkey "\e\e[D" backward-word
bindkey "\e[Z" reverse-menu-complete # Shift+Tab
# for rxvt
bindkey "\e[7~" beginning-of-line # Home
bindkey "\e[8~" end-of-line # End
# for non RH/Debian xterm, can't hurt for RH/Debian xterm
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
# for freebsd console
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line
# for guake
bindkey "\eOF" end-of-line
bindkey "\eOH" beginning-of-line
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
bindkey "\e[3~" delete-char # Del
# alt-s => bitch,
alias bitch,=sudo
insert_sudo () { zle beginning-of-line; zle -U "bitch, " }
zle -N insert-sudo insert_sudo
bindkey "^[s" insert-sudo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment