From 463ec2576725a6d020c4ba5bc08d877c16faea7b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 19 Jun 2015 16:04:48 +0200 Subject: [PATCH] Update zshrc files --- zsh/aliases.zsh | 70 ++++++++++++++++++++++++++---------- zsh/functions.zsh | 28 +++++++++++++++ zsh/functions/_lsarchive | 13 +++++++ zsh/functions/_unarchive | 13 +++++++ zsh/functions/lsarchive | 55 ++++++++++++++++++++++++++++ zsh/functions/unarchive | 78 ++++++++++++++++++++++++++++++++++++++++ zsh/keybinds.zsh | 16 +-------- zshrc | 43 +++++++++------------- 8 files changed, 257 insertions(+), 59 deletions(-) create mode 100644 zsh/functions.zsh create mode 100755 zsh/functions/_lsarchive create mode 100755 zsh/functions/_unarchive create mode 100755 zsh/functions/lsarchive create mode 100755 zsh/functions/unarchive diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 44fade6c..9cfe2f5a 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -1,27 +1,33 @@ -#!/bin/zsh - export p=~/Dropbox/projects +alias -g ...="../.." +alias -g ....="../../.." +alias -g .....="../../../.." + alias q=exit alias clr=clear alias sudo='sudo ' -# Homebrew -alias br='brew' -alias bru='brew update && brew upgrade --all' - # Tools -alias codekit='open -a CodeKit' alias ag='nocorrect noglob ag' -alias ls="ls -G" alias l="ls -l" -alias ll="ls -l" +alias ll="ls -1" +alias la="ls -la" alias ln="ln -v" # Verbose ln alias wget='wget -c' # Resume dl if possible alias rsyncd='rsync -va --delete' # Hard sync two directories zman() { PAGER="less -g -s '+/^ "$1"'" man zshall; } mkd() { mkdir "$1" && cd "$1"; } +j() { + local fasd_ret="$(fasd -i -d "$@")" + if [[ -d "$fasd_ret" ]]; then + cd "$fasd_ret" + else + print "$fasd_ret" + fi +} + # transmission-remote if is-callable 'transmission-remote'; then alias bt='transmission-remote server' @@ -43,12 +49,8 @@ if is-callable 'transmission-remote'; then fi # Editors -v() { [ $# -eq 0 ] && vim . || vim $@ } -e() { # emacs - local input - [ ! $# -eq 0 ] && input=$@ - emacsclient -n ${input:-.} -} +v() { vim ${@:-.}; } # Open in vim +e() { emacsclient -n ${@:-.}; } # Open in emacs (daemon) ee() { # emacs in project root if git root 2>/dev/null; then e "$(git rev-parse --show-toplevel)" @@ -68,9 +70,6 @@ alias b='bundle' alias be='bundle exec' alias bi='bundle install -path vendor' -alias c11='clang++ -std=c++11 -stdlib=libc++' -alias eclimd='/Applications/eclipse/eclimd' - # Build tools alias rk='noglob rake' alias rkg='noglob rake -g' @@ -82,9 +81,11 @@ g() { [ $# -eq 0 ] && git status --short || git $* } alias gi='git init' alias gs='git status' +alias gsu='git submodule' alias gco='git checkout' alias gc='git commit' alias gcm='noglob git commit -m' +alias gcam='noglob git commit --amend -m' alias gd='git diff' alias gp='git push' alias gl='git pull' @@ -93,6 +94,7 @@ alias ge='git exec' alias gb='git branch' alias gap='git add --patch' alias gr='git reset "HEAD^"' +alias gre='git remote' # Tmux if is-callable 'tmux'; then @@ -107,3 +109,35 @@ if is-callable 'tmux'; then # New instance attached to old session alias tn='tmux new-session -t $(hostname)' fi + +if is-mac; then + alias o='open' + alias ls="ls -G" + + alias c11='clang++ -std=c++11 -stdlib=libc++' + alias eclimd='/Applications/eclipse/eclimd' + + # Homebrew + alias br='brew' + alias bru='brew update && brew upgrade --all' + alias brc='brew cask' + alias codekit='open -a CodeKit' + + # Quicklook + ql() { (( $# > 0 )) && qlmanage -p "$@" &> /dev/null; } +elif is-cygwin; then + alias o='cygstart' + alias pbcopy='tee > /dev/clipboard' + alias pbpaste='cat /dev/clipboard' +else + alias o='xdg-open' + alias ls="ls --color=auto" + + if (( $+commands[xclip] )); then + alias pbcopy='xclip -selection clipboard -in' + alias pbpaste='xclip -selection clipboard -out' + elif (( $+commands[xsel] )); then + alias pbcopy='xsel --clipboard --input' + alias pbpaste='xsel --clipboard --output' + fi +fi diff --git a/zsh/functions.zsh b/zsh/functions.zsh new file mode 100644 index 00000000..16b55b0a --- /dev/null +++ b/zsh/functions.zsh @@ -0,0 +1,28 @@ +is-callable() { + (( $+commands[$1] )) || (( $+functions[$1] )) || (( $+aliases[$1] )) +} + +cache() { + is-callable "$1" || return 1 + local cache="$HOME/.zsh/cache/$1-cache" + if [ ! -s "$cache" ]; then + echo "Caching $1" + $@ >| "$cache" 2> /dev/null + fi + source $cache + unset cache +} + +is-mac() { + [[ "$OSTYPE" == "darwin"* ]] +} + +is-deb() { + [[ "$OSTYPE" == "linux-gnu" ]] +} + +is-cygwin() { + [[ "$OSTYPE" == "cygwin"* ]] +} + +fpath=("${0:h}/functions" $fpath) diff --git a/zsh/functions/_lsarchive b/zsh/functions/_lsarchive new file mode 100755 index 00000000..00f83e05 --- /dev/null +++ b/zsh/functions/_lsarchive @@ -0,0 +1,13 @@ +#compdef lsarchive +#autoload + +# +# Completes lsarchive. +# +# Authors: +# Sorin Ionescu +# + +_arguments \ + '(-v --verbose)'{-v,--remove}'[verbose archive listing]' \ + "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|rar|7z)(-.)'" && return 0 diff --git a/zsh/functions/_unarchive b/zsh/functions/_unarchive new file mode 100755 index 00000000..aceb27b6 --- /dev/null +++ b/zsh/functions/_unarchive @@ -0,0 +1,13 @@ +#compdef unarchive +#autoload + +# +# Completes unarchive. +# +# Authors: +# Sorin Ionescu +# + +_arguments \ + '(-r --remove)'{-r,--remove}'[remove archive]' \ + "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|rar|7z|deb)(-.)'" && return 0 diff --git a/zsh/functions/lsarchive b/zsh/functions/lsarchive new file mode 100755 index 00000000..7ac61450 --- /dev/null +++ b/zsh/functions/lsarchive @@ -0,0 +1,55 @@ +# +# Lists the contents of archives. +# +# Authors: +# Sorin Ionescu +# + +local verbose + +if (( $# == 0 )); then + cat >&2 <. +EOF +fi + +if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then + verbose=0 + shift +fi + +while (( $# > 0 )); do + if [[ ! -s "$1" ]]; then + print "$0: file not valid: $1" >&2 + shift + continue + fi + + case "$1:l" in + (*.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;; + (*.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;; + (*.tar.xz|*.txz) tar --xz --help &> /dev/null \ + && tar --xz -t${verbose:+v}f "$1" \ + || xzcat "$1" | tar t${verbose:+v}f - ;; + (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \ + && tar --lzma -t${verbose:+v}f "$1" \ + || lzcat "$1" | tar x${verbose:+v}f - ;; + (*.tar) tar t${verbose:+v}f "$1" ;; + (*.zip) unzip -l${verbose:+v} "$1" ;; + (*.rar) unrar &> /dev/null \ + && unrar ${${verbose:+v}:-l} "$1" \ + || rar ${${verbose:+v}:-l} "$1" ;; + (*.7z) 7za l "$1" ;; + (*) + print "$0: cannot list: $1" >&2 + success=1 + ;; + esac + + shift +done diff --git a/zsh/functions/unarchive b/zsh/functions/unarchive new file mode 100755 index 00000000..f1b4224a --- /dev/null +++ b/zsh/functions/unarchive @@ -0,0 +1,78 @@ +# +# Extracts the contents of archives. +# +# Authors: +# Sorin Ionescu +# + +local remove_archive +local success +local file_name +local extract_dir + +if (( $# == 0 )); then + cat >&2 <. +EOF +fi + +remove_archive=1 +if [[ "$1" == "-r" || "$1" == "--remove" ]]; then + remove_archive=0 + shift +fi + +while (( $# > 0 )); do + if [[ ! -s "$1" ]]; then + print "$0: file not valid: $1" >&2 + shift + continue + fi + + success=0 + file_name="${1:t}" + extract_dir="${file_name:r}" + case "$1:l" in + (*.tar.gz|*.tgz) tar xvzf "$1" ;; + (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;; + (*.tar.xz|*.txz) tar --xz --help &> /dev/null \ + && tar --xz -xvf "$1" \ + || xzcat "$1" | tar xvf - ;; + (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \ + && tar --lzma -xvf "$1" \ + || lzcat "$1" | tar xvf - ;; + (*.tar) tar xvf "$1" ;; + (*.gz) gunzip "$1" ;; + (*.bz2) bunzip2 "$1" ;; + (*.xz) unxz "$1" ;; + (*.lzma) unlzma "$1" ;; + (*.Z) uncompress "$1" ;; + (*.zip) unzip "$1" -d $extract_dir ;; + (*.rar) unrar &> /dev/null \ + && unrar x -ad "$1" \ + || rar x -ad "$1" ;; + (*.7z) 7za x "$1" ;; + (*.deb) + mkdir -p "$extract_dir/control" + mkdir -p "$extract_dir/data" + cd "$extract_dir"; ar vx "../${1}" > /dev/null + cd control; tar xzvf ../control.tar.gz + cd ../data; tar xzvf ../data.tar.gz + cd ..; rm *.tar.gz debian-binary + cd .. + ;; + (*) + print "$0: cannot extract: $1" >&2 + success=1 + ;; + esac + + (( success = $success > 0 ? $success : $? )) + (( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1" + shift +done diff --git a/zsh/keybinds.zsh b/zsh/keybinds.zsh index 8d0e4c8e..b601893c 100644 --- a/zsh/keybinds.zsh +++ b/zsh/keybinds.zsh @@ -8,8 +8,6 @@ bindkey -M viins '^[b' backward-word bindkey -M vicmd 'yy' vi-yank-whole-line bindkey -M vicmd 'Y' vi-yank-eol -bindkey -M vicmd '^r' redo - bindkey -M viins ' ' magic-space bindkey -M viins 'jk' vi-cmd-mode @@ -31,14 +29,12 @@ bindkey '^[[A' history-substring-search-up bindkey '^[[B' history-substring-search-down]]]] # Edit command in an external editor. -bindkey -M vicmd "v" edit-command-line +bindkey -M vicmd "R" edit-command-line # # Undo/Redo bindkey -M vicmd "u" undo bindkey -M vicmd "$key_info[Control]R" redo -bindkey -M viins "." expand-dot-to-parent-directory-path - # Completing words in buffer in tmux if [ -n "$TMUX" ]; then _tmux_pane_words() { @@ -62,13 +58,3 @@ if [ -n "$TMUX" ]; then zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}' fi - -# Expands .... to ../.. -function expand-dot-to-parent-directory-path { - if [[ $LBUFFER = *.. ]]; then - LBUFFER+='/..' - else - LBUFFER+='.' - fi -} -zle -N expand-dot-to-parent-directory-path diff --git a/zshrc b/zshrc index f2b53381..64966dd1 100644 --- a/zshrc +++ b/zshrc @@ -1,47 +1,38 @@ -function is-callable { - (( $+commands[$1] )) || (( $+functions[$1] )) || (( $+aliases[$1] )) -} +### zshrc +# By Henrik Lissner +# Uses zgen to manage plugins -# Source component rcfiles -if [[ -z "$EMACS" ]]; then +export PATH="$HOME/.rbenv/bin:$HOME/.pyenv/bin:$PATH" + +source ~/.zsh/functions.zsh +source ~/.zsh/aliases.zsh + +# if not running through emacs' shell-command +if [ -z "$EMACS" ]; then source ~/.zsh/zgen/zgen.zsh if ! zgen saved; then echo "Creating zgen save" - + zgen load zsh-users/zsh-syntax-highlighting zgen load zsh-users/zsh-history-substring-search zgen load zsh-users/zsh-completions src - zgen load clvv/fasd zgen load hchbaw/opp.zsh zgen load Tarrasch/zsh-bd zgen load houjunchen/zsh-vim-mode - + zgen save fi - - source ~/.zsh/aliases.zsh + source ~/.zsh/config.zsh + source ~/.zsh/completion.zsh source ~/.zsh/keybinds.zsh source ~/.zsh/prompt.zsh - fasd_cache="$HOME/.fasd-cache" - if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then - fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install >| "$fasd_cache" - fi - source "$fasd_cache" - unset fasd_cache + cache fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install fi -## PATHS ############################################### -if [ -d ~/.rbenv ]; then - export PATH=~/.rbenv/bin:$PATH - eval "$(rbenv init - --no-rehash)" -fi - -if [ -d ~/.pyenv ]; then - export PATH=~/.pyenv/bin:~/.pyenv/shims:$PATH - eval "$(pyenv init - --no-rehash)" -fi +cache rbenv init - --no-rehash +cache pyenv init - --no-rehash export ANDROID_HOME=/usr/local/opt/android-sdk export ANDROID_SDK=/usr/local/Cellar/android-sdk/24.2