From 2abcd0977c95bc84d227d60ff5b9ae33ea3e1949 Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Sat, 5 Dec 2015 15:37:09 +0100 Subject: [PATCH] zsh -> bash We lost this battle, but why sour faces? --- .bash_colors | 114 +++++++++++++------------- .bashrc | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++- .profile | 1 + .rc | 209 ----------------------------------------------- .zshrc | 94 --------------------- 5 files changed, 281 insertions(+), 361 deletions(-) create mode 100644 .profile delete mode 100644 .rc delete mode 100644 .zshrc diff --git a/.bash_colors b/.bash_colors index 61843e8..33f4c4f 100644 --- a/.bash_colors +++ b/.bash_colors @@ -1,73 +1,73 @@ # color constants # Reset -Color_Off='\e[0m' # Text Reset +Color_Off='\033[0m' # Text Reset # Regular Colors -Black='\e[0;30m' # Black -Red='\e[0;31m' # Red -Green='\e[0;32m' # Green -Yellow='\e[0;33m' # Yellow -Blue='\e[0;34m' # Blue -Purple='\e[0;35m' # Purple -Cyan='\e[0;36m' # Cyan -White='\e[0;37m' # White +Black='\033[0;30m' # Black +Red='\033[0;31m' # Red +Green='\033[0;32m' # Green +Yellow='\033[0;33m' # Yellow +Blue='\033[0;34m' # Blue +Purple='\033[0;35m' # Purple +Cyan='\033[0;36m' # Cyan +White='\033[0;37m' # White # Bold -BBlack='\e[1;30m' # Black -BRed='\e[1;31m' # Red -BGreen='\e[1;32m' # Green -BYellow='\e[1;33m' # Yellow -BBlue='\e[1;34m' # Blue -BPurple='\e[1;35m' # Purple -BCyan='\e[1;36m' # Cyan -BWhite='\e[1;37m' # White +BBlack='\033[1;30m' # Black +BRed='\033[1;31m' # Red +BGreen='\033[1;32m' # Green +BYellow='\033[1;33m' # Yellow +BBlue='\033[1;34m' # Blue +BPurple='\033[1;35m' # Purple +BCyan='\033[1;36m' # Cyan +BWhite='\033[1;37m' # White # Underline -UBlack='\e[4;30m' # Black -URed='\e[4;31m' # Red -UGreen='\e[4;32m' # Green -UYellow='\e[4;33m' # Yellow -UBlue='\e[4;34m' # Blue -UPurple='\e[4;35m' # Purple -UCyan='\e[4;36m' # Cyan -UWhite='\e[4;37m' # White +UBlack='\033[4;30m' # Black +URed='\033[4;31m' # Red +UGreen='\033[4;32m' # Green +UYellow='\033[4;33m' # Yellow +UBlue='\033[4;34m' # Blue +UPurple='\033[4;35m' # Purple +UCyan='\033[4;36m' # Cyan +UWhite='\033[4;37m' # White # Background -On_Black='\e[40m' # Black -On_Red='\e[41m' # Red -On_Green='\e[42m' # Green -On_Yellow='\e[43m' # Yellow -On_Blue='\e[44m' # Blue -On_Purple='\e[45m' # Purple -On_Cyan='\e[46m' # Cyan -On_White='\e[47m' # White +On_Black='\033[40m' # Black +On_Red='\033[41m' # Red +On_Green='\033[42m' # Green +On_Yellow='\033[43m' # Yellow +On_Blue='\033[44m' # Blue +On_Purple='\033[45m' # Purple +On_Cyan='\033[46m' # Cyan +On_White='\033[47m' # White # High Intensty -IBlack='\e[0;90m' # Black -IRed='\e[0;91m' # Red -IGreen='\e[0;92m' # Green -IYellow='\e[0;93m' # Yellow -IBlue='\e[0;94m' # Blue -IPurple='\e[0;95m' # Purple -ICyan='\e[0;96m' # Cyan -IWhite='\e[0;97m' # White +IBlack='\033[0;90m' # Black +IRed='\033[0;91m' # Red +IGreen='\033[0;92m' # Green +IYellow='\033[0;93m' # Yellow +IBlue='\033[0;94m' # Blue +IPurple='\033[0;95m' # Purple +ICyan='\033[0;96m' # Cyan +IWhite='\033[0;97m' # White # Bold High Intensty -BIBlack='\e[1;90m' # Black -BIRed='\e[1;91m' # Red -BIGreen='\e[1;92m' # Green -BIYellow='\e[1;93m' # Yellow -BIBlue='\e[1;94m' # Blue -BIPurple='\e[1;95m' # Purple -BICyan='\e[1;96m' # Cyan -BIWhite='\e[1;97m' # White +BIBlack='\033[1;90m' # Black +BIRed='\033[1;91m' # Red +BIGreen='\033[1;92m' # Green +BIYellow='\033[1;93m' # Yellow +BIBlue='\033[1;94m' # Blue +BIPurple='\033[1;95m' # Purple +BICyan='\033[1;96m' # Cyan +BIWhite='\033[1;97m' # White # High Intensty backgrounds -On_IBlack='\e[0;100m' # Black -On_IRed='\e[0;101m' # Red -On_IGreen='\e[0;102m' # Green -On_IYellow='\e[0;103m' # Yellow -On_IBlue='\e[0;104m' # Blue -On_IPurple='\e[10;95m' # Purple -On_ICyan='\e[0;106m' # Cyan -On_IWhite='\e[0;107m' # White +On_IBlack='\033[0;100m' # Black +On_IRed='\033[0;101m' # Red +On_IGreen='\033[0;102m' # Green +On_IYellow='\033[0;103m' # Yellow +On_IBlue='\033[0;104m' # Blue +On_IPurple='\033[10;95m' # Purple +On_ICyan='\033[0;106m' # Cyan +On_IWhite='\033[0;107m' # White diff --git a/.bashrc b/.bashrc index 4f57fa4..cfe35f7 100644 --- a/.bashrc +++ b/.bashrc @@ -1,3 +1,4 @@ +. /etc/profile # colors . ~/.bash_colors @@ -43,4 +44,225 @@ PS1="$PS1"'$(if [ ${#PWD} -lt 6 ]; then echo -ne "\[$BRed\]"; else echo -ne "\[$ PS1="$PS1\[$Color_Off\]\[$BGreen\]]\\$\[$Color_Off\] " -source ~/.rc +export EDITOR=vim +export BROWSER=chromium +export PAGER='less -R -F -X -S -n -i -m' + +export GOPATH=~/src/go +export GOROOT=~/pkg/go +export PATH="$PATH:$HOME/bin:$GOROOT/bin:$GOPATH/bin" +if [ -d $HOME/.gem/ruby ]; then + export PATH="$PATH:$(echo $HOME/.gem/ruby/*/bin | tr ' ' :)" +fi +export GIT_COMMITTER_NAME='Artem Sheremet' +export GIT_COMMITTER_EMAIL='dot.doom@gmail.com' +export DOOMWADDIR=~/dist/games/doom/wad +export DE=generic +export CLICOLOR=1 + +alias ls='ls -hF --color=auto' +alias pgrep='pgrep -lf' +alias crontab='crontab -i' +alias gmake='make' +alias nc='nc -vv' +alias snc='openssl s_client -connect ' +alias vsnc='openssl s_client -showcerts -state -msg -debug -connect ' +alias killall='killall -v -r' +alias scrot='scrot -e "mv \$f ~/Pictures/ 2>/dev/null" -cd 5' +alias qiv='qiv -fml -M' +alias qivr='qiv -u' +alias grep='grep --line-buffered --color=auto' +alias fgrep='grep -Frn --color=always' +alias figrep='fgrep -i' +alias svn='svn --no-auth-cache' +alias mysql='mysql --select_limit=1000' +alias ka='killall' +alias fsck='fsck -C' +alias pager=$PAGER +alias npager='pager -N' +alias l='ls -lA' +alias ll='ls -la' +alias la='cat /proc/loadavg' +alias ipt='iptables -nvL --line-numbers' +alias ip6t='ip6tables -nvL --line-numbers' +alias psa='ps axfo pid,euser,bsdstart,vsz,rss,bsdtime,args' +alias parent='ps -p $PPID -o comm=' +alias dbgrep='dbgrep.pl -vpuroot' +alias tcpdump='tcpdump -l' +alias pacman='pacman --color auto' +alias xo=xdg-open +alias ag='ag -C 2 --pager=$PAGER --smart-case' +alias prepend-timestamp='gawk "{ print strftime(\"[%Y-%m-%d %H:%M:%S]\"), \$0; fflush() }"' + +function ds() { + du -sh "$@" | sort -rh +} + +function i4() { + if [ $# -eq 0 ]; then + curl --silent http://ipecho.net/plain; echo + else + ip addr show "$1" | sed -nr 's/\s+inet ([0-9.]+)\/.*/\1/p' + fi +} + +# mysqldump extraction +function mysql_extract_db() { + sed -n "/^-- Current Database: \`$1\`/,/^-- Current Database: \`/p" +} +function mysql_extract_table() { + sed -n "/^-- Table structure for table \`$1\`/,/^-- Table structure for table \`/p" +} + +# LOL protect me +alias mv='mv -i' +alias cp='cp -i' +alias rm='rm -i' + +# git aliases +alias gb='git branch' +alias gba='git branch -av' +alias gc='git commit -v' +alias gd='git di' +alias gdc='gd --cached' +alias gdm='gd master --stat --relative' +alias gl='git pull' +alias gp='git push' +alias gst='git status' + +# sudo +alias sudo='sudo -E ' +alias su='su -m' + +# useful stuff +[ -z "$VIM_ORIGINAL" ] && VIM_ORIGINAL="$(which vim)" +function vim() { + if [ "$TERM" = "linux" ]; then + local COMPAT_TERM=$TERM + else + local COMPAT_TERM="xterm-256color" + fi + # we only handle single-argument VIM + if [ $# -eq 1 ]; then + if [ -e "$1" ]; then + # editing an existing file + FILENAME="$1" + else + # trying to create new file, will check it's directory for WRITE access + FILENAME="`dirname $1 2>/dev/null`" + fi + + if [ -w "$FILENAME" ]; then + # yahoo! writable + TERM=$COMPAT_TERM "$VIM_ORIGINAL" "$1" + else + echo 'this file will be opened with sudo' + TERM=$COMPAT_TERM sudo "$VIM_ORIGINAL" "$1" || "$VIM_ORIGINAL" "$1" + fi + else + TERM=$COMPAT_TERM "$VIM_ORIGINAL" $* + fi +} + +function dl() { + for entry in "$@"; do + printf '%-7d %s\n' $(find $entry | wc -l) "$entry" + done | sort -rn +} + +function mkcd() { + mkdir -p "$@" + cd "$@" +} +function cpcd() { + cp "$@" + cd $_ +} +function cdls() { + cd "$1" + shift + ls "$@" +} + +function fin() { + local filename="$1" + find . -iname "*$filename*" +} + +function tt() { + tail -f "$@" | prepend-timestamp +} + +function ip4tables-fwd() { + if [ $# -eq 1 ]; then + local SRC_ADDR="$(i4)" + local DST_ADDR="$1" + elif [ $# -eq 2 ]; then + local SRC_ADDR="$1" + local DST_ADDR="$2" + else + echo "Usage: $0 [] " >&2 + return 1 + fi + + local SRC_HOST=${SRC_ADDR/:*/} + if [ "$SRC_HOST" != "$SRC_ADDR" ]; then + local SRC_PORT=${SRC_ADDR/*:/} + fi + + local DST_HOST=${DST_ADDR/:*/} + if [ "$DST_HOST" = "$DST_ADDR" ]; then + if [ -z "$SRC_PORT" ]; then + echo "Cannot detect forwarding port. At least one address must have it's port specified." >&2 + return 1 + fi + local DST_PORT=$SRC_PORT + else + local DST_PORT=${DST_ADDR/*:/} + fi + + [ -z "$SRC_PORT" ] && local SRC_PORT=$DST_PORT + + echo "To forward <$SRC_HOST> port <$SRC_PORT> to <$DST_HOST> port <$DST_PORT>: +iptables -t nat -A PREROUTING -d $SRC_HOST -p tcp --dport $SRC_PORT -j DNAT --to-destination $DST_HOST:$DST_PORT +iptables -t nat -A POSTROUTING -d $DST_HOST -p tcp --dport $DST_PORT -j SNAT --to-source $SRC_HOST +" +} + +if [ -r ~/.bashrc_local ]; then + . ~/.bashrc_local +fi + +if [ -x "$(which dircolors 2>/dev/null)" ]; then + eval $(dircolors) +fi + +case $- in + *i*) + # only with interactive non-sudo shell + if [ -n "$SSH_CONNECTION" ] && [ -z "$SUDO_UID" ]; then + [ "$(parent)" = "screen" ] || screen -RR + fi + ;; +esac + +function title() { + [ "$DISABLE_AUTO_TITLE" != "true" ] || return + if [[ "$TERM" == screen* ]]; then + echo -en "\033k$1\033\\" + elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then + # Window title + [ -n "$2" ] && echo -en "\033]2;$2\a" + # Tab title (gnome-terminal, konsole) + echo -en "\033]1;$1\a" + fi +} + +trap 'title "$BASH_COMMAND"' DEBUG + +# TODO: delete this +upload() { + echo http://bin.dget.cc/$(curl -X POST --data-binary @"$1" http://bin.dget.cc/ | tail -3 | head -1 | cut -d'"' -f2) +} + +# vim: ft=sh diff --git a/.profile b/.profile new file mode 100644 index 0000000..4b18bd1 --- /dev/null +++ b/.profile @@ -0,0 +1 @@ +source $HOME/.bashrc diff --git a/.rc b/.rc deleted file mode 100644 index c7c62bc..0000000 --- a/.rc +++ /dev/null @@ -1,209 +0,0 @@ -. /etc/profile - -export EDITOR=vim -export BROWSER=chromium -export PAGER='less -R -F -X -S -n -i -m' - -export GOPATH=~/src/go -export GOROOT=~/pkg/go -export PATH="$PATH:$HOME/bin:$GOROOT/bin:$GOPATH/bin" -if [ -d $HOME/.gem/ruby ]; then - export PATH="$PATH:$(echo $HOME/.gem/ruby/*/bin | tr ' ' :)" -fi -export GIT_COMMITTER_NAME='Artem Sheremet' -export GIT_COMMITTER_EMAIL='dot.doom@gmail.com' -export DOOMWADDIR=~/dist/games/doom/wad -export DE=generic -export CLICOLOR=1 - -alias ls='ls -hF --color=auto' -alias pgrep='pgrep -lf' -alias crontab='crontab -i' -alias gmake='make' -alias nc='nc -vv' -alias snc='openssl s_client -connect ' -alias vsnc='openssl s_client -showcerts -state -msg -debug -connect ' -alias killall='killall -v -r' -alias scrot='scrot -e "mv \$f ~/Pictures/ 2>/dev/null" -cd 5' -alias qiv='qiv -fml -M' -alias qivr='qiv -u' -alias grep='grep --line-buffered --color=auto' -alias fgrep='grep -Frn --color=always' -alias figrep='fgrep -i' -alias svn='svn --no-auth-cache' -alias mysql='mysql --select_limit=1000' -alias ka='killall' -alias fsck='fsck -C' -alias pager=$PAGER -alias npager='pager -N' -alias l='ls -lA' -alias ll='ls -la' -alias la='cat /proc/loadavg' -alias ipt='iptables -nvL --line-numbers' -alias ip6t='ip6tables -nvL --line-numbers' -alias psa='ps axfo pid,euser,bsdstart,vsz,rss,bsdtime,args' -alias parent='ps -p $PPID -o comm=' -alias dbgrep='dbgrep.pl -vpuroot' -alias tcpdump='tcpdump -l' -alias pacman='pacman --color auto' -alias xo=xdg-open -alias ag='ag -C 2 --pager=$PAGER --smart-case' -alias prepend-timestamp='gawk "{ print strftime(\"[%Y-%m-%d %H:%M:%S]\"), \$0; fflush() }"' - -function ds() { - du -sh "$@" | sort -rh -} - -function i4() { - if [ $# -eq 0 ]; then - curl --silent http://ipecho.net/plain; echo - else - ip addr show "$1" | sed -nr 's/\s+inet ([0-9.]+)\/.*/\1/p' - fi -} - -# mysqldump extraction -function mysql_extract_db() { - sed -n "/^-- Current Database: \`$1\`/,/^-- Current Database: \`/p" -} -function mysql_extract_table() { - sed -n "/^-- Table structure for table \`$1\`/,/^-- Table structure for table \`/p" -} - -# LOL protect me -alias mv='mv -i' -alias cp='cp -i' -alias rm='rm -i' - -# git aliases -alias gb='git branch' -alias gba='git branch -av' -alias gc='git commit -v' -alias gd='git di' -alias gdc='gd --cached' -alias gdm='gd master --stat --relative' -alias gl='git pull' -alias gp='git push' -alias gst='git status' - -# sudo -alias sudo='sudo -E ' -alias su='su -m' - -# useful stuff -[ -z "$VIM_ORIGINAL" ] && VIM_ORIGINAL="$(which vim)" -function vim() { - if [ "$TERM" = "linux" ]; then - local COMPAT_TERM=$TERM - else - local COMPAT_TERM="xterm-256color" - fi - # we only handle single-argument VIM - if [ $# -eq 1 ]; then - if [ -e "$1" ]; then - # editing an existing file - FILENAME="$1" - else - # trying to create new file, will check it's directory for WRITE access - FILENAME="`dirname $1 2>/dev/null`" - fi - - if [ -w "$FILENAME" ]; then - # yahoo! writable - TERM=$COMPAT_TERM "$VIM_ORIGINAL" "$1" - else - echo 'this file will be opened with sudo' - TERM=$COMPAT_TERM sudo "$VIM_ORIGINAL" "$1" || "$VIM_ORIGINAL" "$1" - fi - else - TERM=$COMPAT_TERM "$VIM_ORIGINAL" $* - fi -} - -function dl() { - for entry in "$@"; do - printf '%-7d %s\n' $(find $entry | wc -l) "$entry" - done | sort -rn -} - -function mkcd() { - mkdir -p "$@" - cd "$@" -} -function cpcd() { - cp "$@" - cd $_ -} -function cdls() { - cd "$1" - shift - ls "$@" -} - -function fin() { - local filename="$1" - find . -iname "*$filename*" -} - -function tt() { - tail -f "$@" | prepend-timestamp -} - -function ip4tables-fwd() { - if [ $# -eq 1 ]; then - local SRC_ADDR="$(i4)" - local DST_ADDR="$1" - elif [ $# -eq 2 ]; then - local SRC_ADDR="$1" - local DST_ADDR="$2" - else - echo "Usage: $0 [] " >&2 - return 1 - fi - - local SRC_HOST=${SRC_ADDR/:*/} - if [ "$SRC_HOST" != "$SRC_ADDR" ]; then - local SRC_PORT=${SRC_ADDR/*:/} - fi - - local DST_HOST=${DST_ADDR/:*/} - if [ "$DST_HOST" = "$DST_ADDR" ]; then - if [ -z "$SRC_PORT" ]; then - echo "Cannot detect forwarding port. At least one address must have it's port specified." >&2 - return 1 - fi - local DST_PORT=$SRC_PORT - else - local DST_PORT=${DST_ADDR/*:/} - fi - - [ -z "$SRC_PORT" ] && local SRC_PORT=$DST_PORT - - echo "To forward <$SRC_HOST> port <$SRC_PORT> to <$DST_HOST> port <$DST_PORT>: -iptables -t nat -A PREROUTING -d $SRC_HOST -p tcp --dport $SRC_PORT -j DNAT --to-destination $DST_HOST:$DST_PORT -iptables -t nat -A POSTROUTING -d $DST_HOST -p tcp --dport $DST_PORT -j SNAT --to-source $SRC_HOST -" -} - -if [ -r ~/.rc_local ]; then - . ~/.rc_local -fi - -if [ -x "$(which dircolors 2>/dev/null)" ]; then - eval $(dircolors) -fi - -case $- in - *i*) - # only with interactive non-sudo shell - if [ -n "$SSH_CONNECTION" ] && [ -z "$SUDO_UID" ]; then - [ "$(parent)" = "screen" ] || screen -RR - fi - ;; -esac - -upload() { - echo http://bin.dget.cc/$(curl -X POST --data-binary @"$1" http://bin.dget.cc/ | tail -3 | head -1 | cut -d'"' -f2) -} - -# vim: ft=sh diff --git a/.zshrc b/.zshrc deleted file mode 100644 index 8a38ebc..0000000 --- a/.zshrc +++ /dev/null @@ -1,94 +0,0 @@ -source ~/.rc - -# zsh -zstyle ':completion:*' completer _complete _ignored _approximate -zstyle ':completion:*' max-errors 2 -zstyle ':completion:*' menu select -zstyle ':completion:*' completealiases -zstyle :compinstall filename ~/.zshrc - -autoload -Uz compinit -compinit -# End of lines added by compinstall -# Lines configured by zsh-newuser-install -export HISTFILE=~/.histfile -export HISTSIZE=10000 -export SAVEHIST=$HISTSIZE -setopt hist_ignore_all_dups -unsetopt extendedglob -setopt autocd -setopt rmstarsilent -bindkey -e -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 -# Search backwards and forwards with a pattern -bindkey -M vicmd '/' history-incremental-pattern-search-backward -bindkey -M vicmd '?' history-incremental-pattern-search-forward -# set up for insert mode too -bindkey -M viins '^R' history-incremental-pattern-search-backward -bindkey -M viins '^F' history-incremental-pattern-search-forward - -#setopt share_history -setopt inc_append_history - -autoload -U promptinit -promptinit -prompt clint - -# title -function title() { - [ "$DISABLE_AUTO_TITLE" != "true" ] || return - if [[ "$TERM" == screen* ]]; then - print -Pn "\ek$1:q\e\\" - elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then - # Window title - [ -n "$2" ] && print -Pn "\e]2;$2:q\a" - # Tab title (gnome-terminal, konsole) - print -Pn "\e]1;$1:q\a" - fi -} - -function terminal_title_at_prompt { - # "pwd" in tab, "user@host: pwd" in window - title "%15<..<%~%<<" "%n@%m: %~" -} - -function terminal_title_on_command { - title "$1" "$1" -} - -__git_files () { - _wanted files expl 'local files' _files -} - -autoload -U add-zsh-hook -add-zsh-hook precmd terminal_title_at_prompt -add-zsh-hook preexec terminal_title_on_command - -alias -s avi=smplayer