dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit ad53dc111642ba1cbffe2fb7b2985fdd7ab1dd28
parent 29a976cd487d0432de84af243c1191b4ac75ae35
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 30 May 2018 09:27:42 -0400

Split shell functions and aliases into .commands.sh, use zgen

Diffstat:
Minit/50_zsh.sh | 7+++++--
Alinks/.commands.sh | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlinks/.zshrc | 198+++++++++++++------------------------------------------------------------------
3 files changed, 164 insertions(+), 169 deletions(-)

diff --git a/init/50_zsh.sh b/init/50_zsh.sh @@ -2,7 +2,10 @@ # zsh plugin manager (mkdir -p ~/code && cd ~/code && - if [ ! -d zplug ]; then - git clone https://github.com/zplug/zplug + # if [ ! -d zplug ]; then + # git clone https://github.com/zplug/zplug + # fi + if [ ! -d zgen ]; then + git clone https://github.com/tarjoilija/zgen fi ) diff --git a/links/.commands.sh b/links/.commands.sh @@ -0,0 +1,128 @@ +#!/usr/bin/env zsh +#### FUNCTIONS AND ALIASES + +if [[ "$(uname)" != 'Darwin' ]]; then + function open() { xdg-open $1 &> /dev/null &disown; } + function say() { echo "$@" | festival --tts; } +fi +function lt() { ls -ltrsa "$@" | tail -n $(( $LINES - 10 )); } +function lT() { ls -ltsa "$@" | tail -n $(( $LINES - 10 )); } +function lz() { ls -laShr "$@" | tail -n $(( $LINES - 10 )); } +function lZ() { ls -laSh "$@" | tail -n $(( $LINES - 10 )); } +function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; } +function cgrep() { egrep --color -i "$@|$"; } +function fname() { find . -iname "*$@*"; } +function sayfile() { festival --tts $@; } +function tnew { tmux new-session -As `basename $PWD` } +function w3mtor { + local url + if [ $# -eq 0 ]; then + url="https://check.torproject.org/" + else + url=$1 + fi + torify w3m $url +} +function w3mddg { torify surfraw ddg $@ } +function weather { curl 'wttr.in/?m'; } +function define { curl --silent dict://dict.org/d:$1 } +function news { + local url + if [ $# -eq 0 ]; then + url="https://text.npr.org" + elif [ "$1" = "npr" ]; then + url="https://text.npr.org" + elif [ "$1" = "cnn" ]; then + url="https://lite.cnn.io/en" + else + url=$1 + fi + torify w3m $url +} + +# Start emacs daemon if it is not running, then attach client +function e () { + if [ ! $(pgrep emacs --daemon) ]; then + echo starting emacs daemon + emacsdaemonlog=~/.emacs-daemon.log + [ -f ~/.emacs-daemon.log ] && rm $emacsdaemonlog # delete old logfile + emacs --daemon > $emacsdaemonlog 2>&1 + fi + emacsclient -t +} + +function transfer() { # use transfer.sh to share files over the net + if [ $# -eq 0 ]; then + echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" + return 1 + fi + tmpfile=$( mktemp -t transferXXX ) + if tty -s; then + basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g') + curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile + else + curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile + fi + cat $tmpfile + rm -f $tmpfile + echo "" +} + +alias svim='sudo -e' +alias v='vim' +alias f='fg' +alias vi='vim -u NONE' +alias gs='git status | less' +alias gl='git log --graph --oneline --decorate --all' +alias ga='git add' +alias gd='git diff --' +alias gch='git diff HEAD^..HEAD' +alias gc='git commit --verbose --gpg-sign' +alias gca='git commit --all --verbose --gpg-sign' +alias gp='git push' +alias gpu='git pull' +alias gcgp='git commit --verbose --gpg-sign && git push' +alias gcagp='git commit --all --verbose --gpg-sign && git push' +alias clear='clear && tmux clear-history' +alias ct='ctags -R .' +alias findgrep='find . | grep -i ' +alias lsgrep='ls -la | grep -in ' +alias fixdisplay='export DISPLAY=:0' +alias zshreload="source ~/.zshrc" +alias dotfiles-update="cd ~/code/dotfiles && git pull ; zshreload ; cd -" +alias dotfiles-commit="cd ~/code/dotfiles && git commit -a -S -v ; git push ; cd -" +alias m="make" +alias mc="make clean" +alias me="make edit" +alias 2048='2048 bluered' +alias c='xsel -ib' +alias h='history | tail' +alias ']'='open' +alias l='ls -alFh' +alias la='ls -A' +alias lla='ls -lA' +alias ipython-prof='ipython -m cProfile -s time' +alias python-prof='python -m cProfile -s time' +alias pipupgrade='pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs sudo pip install -U' +alias date-denmark='TZ=Europe/Copenhagen date' +alias date-eastern='TZ=US/Eastern date' +alias date-pacific='TZ=US/Pacific date' +alias date-mountain='TZ=US/Mountain date' +alias date-central='TZ=US/Central date' +alias sha256sum='shasum -a 256' +alias cala="gcalcli agenda" +alias youtube-dl='youtube-dl --format mp4' +alias html="ansifilter -H -f" +alias w3m="w3m -B" + +function cd() { [[ "$1" == "..." ]] && builtin cd ../.. || builtin cd $@; } + +# enable color support of ls and also add handy aliases +if [[ "$(uname)" != 'Darwin' ]]; then + alias ls='ls --color=auto -F' +else + alias ls='ls -G -F' +fi +function chpwd() { ls } + +alias grep='grep --color=auto' diff --git a/links/.zshrc b/links/.zshrc @@ -3,14 +3,10 @@ # zmodload zsh/datetime # PS4='+[$EPOCHREALTIME]%N:%i> ' # set -x +debug_startup=false +[ "$debug_startup" = true ] && zmodload zsh/zprof #### GENERAL -ARCH=$(uname) - -set -o noclobber # prevent overwriting files with > (override with 1>) -set -o vi -bindkey jk vi-cmd-mode - export EDITOR="vim" # Returns whether the given command is executable or aliased. @@ -26,6 +22,19 @@ compinit -d promptinit colors +set -o noclobber # prevent overwriting files with > (override with 1>) +unset AUTO_CD +setopt CORRECT +setopt completealiases +setopt append_history +setopt share_history +setopt hist_verify +setopt hist_ignore_all_dups +setopt interactivecomments # allow in-line comments in zsh prompt +export HISTFILE=~/.zsh-history +export HISTSIZE=$((2 ** 16)) +export SAVEHIST=$((2 ** 17)) + #### ZSH APPEARANCE @@ -88,18 +97,6 @@ ${EXECTIME}\ %{$fg[cyan]%}$(git_branch)\ %{$reset_color%}%n@%m" -unset AUTO_CD -setopt CORRECT -setopt completealiases -setopt append_history -setopt share_history -setopt hist_verify -setopt hist_ignore_all_dups -setopt interactivecomments # allow in-line comments in zsh prompt -export HISTFILE=~/.zsh-history -export HISTSIZE=$((2 ** 16)) -export SAVEHIST=$((2 ** 17)) - zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*' list-colors 'reply=( "=(#b)(*$VAR)(?)*=00=$color[green]=$color[bg-green]" )' zstyle ':completion:*:*:*:*:hosts' list-colors '=*=30;41' @@ -109,7 +106,9 @@ zstyle ':completion:*' menu select #### ZSH KEYBINDS +set -o vi bindkey -v +bindkey jk vi-cmd-mode bindkey '^R' history-incremental-search-backward bindkey "^j" history-beginning-search-backward bindkey "^k" history-beginning-search-forward @@ -163,131 +162,7 @@ bindkey '^g' _editor_fuzzy_grep #### FUNCTIONS AND ALIASES - -if [[ "$ARCH" != 'Darwin' ]]; then - function open() { xdg-open $1 &> /dev/null &disown; } - function say() { echo "$@" | festival --tts; } -fi -function lt() { ls -ltrsa "$@" | tail -n $(( $LINES - 10 )); } -function lT() { ls -ltsa "$@" | tail -n $(( $LINES - 10 )); } -function lz() { ls -laShr "$@" | tail -n $(( $LINES - 10 )); } -function lZ() { ls -laSh "$@" | tail -n $(( $LINES - 10 )); } -function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; } -function cgrep() { egrep --color -i "$@|$"; } -function fname() { find . -iname "*$@*"; } -function sayfile() { festival --tts $@; } -function tnew { tmux new-session -As `basename $PWD` } -function w3mtor { - local url - if [ $# -eq 0 ]; then - url="https://check.torproject.org/" - else - url=$1 - fi - torify w3m $url -} -function w3mddg { torify surfraw ddg $@ } -function weather { curl 'wttr.in/?m'; } -function define { curl --silent dict://dict.org/d:$1 } -function news { - local url - if [ $# -eq 0 ]; then - url="https://text.npr.org" - elif [ "$1" = "npr" ]; then - url="https://text.npr.org" - elif [ "$1" = "cnn" ]; then - url="https://lite.cnn.io/en" - else - url=$1 - fi - torify w3m $url -} - -# Start emacs daemon if it is not running, then attach client -function e () { - if [ ! $(pgrep emacs --daemon) ]; then - echo starting emacs daemon - emacsdaemonlog=~/.emacs-daemon.log - [ -f ~/.emacs-daemon.log ] && rm $emacsdaemonlog # delete old logfile - emacs --daemon > $emacsdaemonlog 2>&1 - fi - emacsclient -t -} - -function transfer() { # use transfer.sh to share files over the net - if [ $# -eq 0 ]; then - echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" - return 1 - fi - tmpfile=$( mktemp -t transferXXX ) - if tty -s; then - basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g') - curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile - else - curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile - fi - cat $tmpfile - rm -f $tmpfile - echo "" -} - -alias svim='sudo -e' -alias v='vim' -alias f='fg' -alias vi='vim -u NONE' -alias gs='git status | less' -alias gl='git log --graph --oneline --decorate --all' -alias ga='git add' -alias gd='git diff --' -alias gch='git diff HEAD^..HEAD' -alias gc='git commit --verbose --gpg-sign' -alias gca='git commit --all --verbose --gpg-sign' -alias gp='git push' -alias gpu='git pull' -alias gcgp='git commit --verbose --gpg-sign && git push' -alias gcagp='git commit --all --verbose --gpg-sign && git push' -alias clear='clear && tmux clear-history' -alias ct='ctags -R .' -alias findgrep='find . | grep -i ' -alias lsgrep='ls -la | grep -in ' -alias fixdisplay='export DISPLAY=:0' -alias zshreload="source ~/.zshrc" -alias dotfiles-update="cd ~/code/dotfiles && git pull ; zshreload ; cd -" -alias dotfiles-commit="cd ~/code/dotfiles && git commit -a -S -v ; git push ; cd -" -alias m="make" -alias mc="make clean" -alias me="make edit" -alias 2048='2048 bluered' -alias c='xsel -ib' -alias h='history | tail' -alias ']'='open' -alias l='ls -alFh' -alias la='ls -A' -alias lla='ls -lA' -alias ipython-prof='ipython -m cProfile -s time' -alias python-prof='python -m cProfile -s time' -alias pipupgrade='pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs sudo pip install -U' -alias date-denmark='TZ=Europe/Copenhagen date' -alias date-eastern='TZ=US/Eastern date' -alias date-pacific='TZ=US/Pacific date' -alias date-mountain='TZ=US/Mountain date' -alias date-central='TZ=US/Central date' -alias sha256sum='shasum -a 256' -alias cala="gcalcli agenda" -alias youtube-dl='youtube-dl --format mp4' -alias html="ansifilter -H -f" -alias w3m="w3m -B" -function cd() { [[ "$1" == "..." ]] && builtin cd ../.. || builtin cd $@; } - -# enable color support of ls and also add handy aliases -if [[ "$ARCH" != 'Darwin' ]]; then - alias ls='ls --color=auto -F' -else - alias ls='ls -G -F' -fi -function chpwd() { ls } - -alias grep='grep --color=auto' +source ~/.commands.sh # open files with certain suffix in $EDITOR when calling their name for suffix in c cc cxx go h html jl js json md py rb rst vim yml @@ -302,35 +177,22 @@ done #### ZSH PLUGINS -if [ -f ~/code/zplug/init.zsh ]; then - - export ZPLUG_HOME=~/code/zplug - source $ZPLUG_HOME/init.zsh +# zgen is faster than zplug +if [ -f ~/code/zgen/zgen.zsh ]; then + source ~/code/zgen/zgen.zsh - zplug "zplug/zplug", hook-build:"zplug --self-manage" - zplug "junegunn/fzf", use:"shell/*.zsh" - zplug "zsh-users/zsh-autosuggestions" - zplug "zsh-users/zsh-completions", lazy:true - zplug "zsh-users/zsh-syntax-highlighting" - zplug "anders-dc/fzf-mpd" + if ! zgen saved; then - if ! zplug check; then - printf "Install? [y/N]: " - if read -q; then - echo; zplug install - fi - fi + echo "Creating a zgen save" - zplug load -else - echo "warning: init.zsh not found in ~/code/zplug" -fi + zgen load "junegunn/fzf" + zgen load "zsh-users/zsh-autosuggestions" + zgen load "zsh-users/zsh-completions" + zgen load "zsh-users/zsh-syntax-highlighting" -## Plugin options -if _has cabal && _has stack; then - GIT_PROMPT_EXECUTABLE='haskell' + zgen save + fi fi -ZSH_THEME_GIT_PROMPT_CACHE=true #### AUTOCOMPLETE @@ -356,3 +218,5 @@ if _has fzf; then --bind='enter:execute:git show --color=always {2} | less -R' \ --bind='ctrl-x:execute:git checkout {2} .'" fi + +[ "$debug_startup" = true ] && zprof || :