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 34a99de33f750a71eb1e3e54a1a6d71f2230f89d
parent 8d3c1018698f1cf0e9f8c794bfc60c3abc25c6ff
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 30 May 2018 14:36:09 -0400

Improve general commands and tmux utility script

Diffstat:
Mlinks/.commands.sh | 185++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mlinks/.profile | 5++++-
Mlinks/.zshrc | 44+++++++++++++++++++-------------------------
Mlinks/bin/tmux-utility.sh | 48+++++++++++++++++++++---------------------------
4 files changed, 162 insertions(+), 120 deletions(-)

diff --git a/links/.commands.sh b/links/.commands.sh @@ -1,11 +1,122 @@ #!/bin/bash + #### FUNCTIONS AND ALIASES + +## cd + +alias cg='c "$(git rev-parse --show-toplevel)"' # cd under git repo +alias ch='cd "$(dirs -lp | sort -u | fzf)"' # cd from history + +# change to directory under pwd +c() { + local dir + dir=$(find "${1:-.}" -type d | grep -v '/\.' | fzf) + + [ -n "$dir" ] && cd "$dir" || return +} + + +## ls + +if [[ "$(uname)" != 'Darwin' ]]; then + alias ls='ls --color=auto -F' +else + alias ls='ls -G -F' +fi +alias l='ls -alFh' +alias la='ls -A' +alias lla='ls -lA' + + +## Open files if [ "$(uname)" != 'Darwin' ]; then open() { xdg-open "$@" &> /dev/null &disown; } say() { echo "$@" | festival --tts; } fi + + +## editor + +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 +} + +alias vi='vim -u NONE' + + +## dotfiles + +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 -" + + +## python + +alias ipython-prof='ipython -m cProfile -s time' +alias python-prof='python -m cProfile -s time' + + + +## make + +alias m="make" +alias mc="make clean" +alias me="make edit" + + +## date + +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' + + +## git + +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' + +# redefine git log alias +alias gl="git log --graph --oneline --decorate --all --color=always | + fzf --ansi +s --preview='git show --color=always {2}' \ + --bind='pgdn:preview-page-down' \ + --bind='pgup:preview-page-up' \ + --bind='enter:execute:git show --color=always {2} | less -R' \ + --bind='ctrl-x:execute:git checkout {2} .'" + + +## grep + +alias grep='grep --color=auto' + + +## speech synthesis + sayfile() { festival --tts "$@"; } + + +## w3m + +alias w3m="w3m -B" w3mtor() { local url if [ $# -eq 0 ]; then @@ -15,9 +126,9 @@ w3mtor() { fi torify w3m "$url" } + w3mddg() { torify surfraw ddg "$@"; } -weather() { curl "wttr.in/?m"; } -define() { curl --silent dict://dict.org/d:"$1"; } + news() { local url if [ $# -eq 0 ]; then @@ -32,17 +143,12 @@ news() { torify w3m "$url" } -# Start emacs daemon if it is not running, then attach client -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 -} +## web services + +alias youtube-dl='youtube-dl --format mp4' +weather() { curl "wttr.in/?m"; } +define() { curl --silent dict://dict.org/d:"$1"; } transfer() { # use transfer.sh to share files over the net if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage: transfer.sh <file>" @@ -61,58 +167,3 @@ transfer() { # use transfer.sh to share files over the net 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 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" - -# 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 - -alias grep='grep --color=auto' diff --git a/links/.profile b/links/.profile @@ -4,6 +4,7 @@ export EDITOR="vim" export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 +# shellcheck source=/dev/null [ -f ~/.secret_env_vars ] && . ~/.secret_env_vars @@ -26,7 +27,8 @@ fi export GOPATH=~/src/golang export PATH=$PATH:$GOPATH/bin -export GPG_TTY=$(tty) +GPG_TTY=$(tty) +export GPG_TTY [ -d ~/pism ] && export PATH=~/pism/bin:$PATH [ -d ~/code/issm/trunk ] && export ISSM_DIR=~/code/issm/trunk @@ -59,6 +61,7 @@ if [ -x "$(command -v fzf)" ]; then fi if [ -f /usr/local/Modules/default/init/zsh ]; then + # shellcheck disable=SC1091 . /usr/local/Modules/default/init/zsh && \ #module load git vim #python paraview ncview matlab ifort anaconda module load git python/2.7.1 diff --git a/links/.zshrc b/links/.zshrc @@ -41,7 +41,7 @@ bindkey '^N' down-line-or-search bindkey '^ ' autosuggest-accept # accept suggestion with ctrl+space # use Ctrl-Z as fg -_fzf-foreground () { +_fzf_foreground() { if [[ $#BUFFER -eq 0 ]]; then BUFFER="fg" zle accept-line @@ -50,8 +50,8 @@ _fzf-foreground () { zle clear-screen fi } -zle -N _fzf-foreground -bindkey '^Z' _fzf-foreground +zle -N _fzf_foreground +bindkey '^Z' _fzf_foreground # launch $EDITOR with Ctrl-e _editor() { @@ -88,19 +88,19 @@ bindkey '^g' _editor_fuzzy_grep for suffix in c cc cxx go graphql h html js json jsx md py rb rs ts tsx vim yml do - alias -s $suffix=$EDITOR + alias -s $suffix=$EDITOR done for suffix in txt log do - alias -s $suffix=$PAGER + alias -s $suffix=$PAGER done #### ZSH APPEARANCE # show execution time of previous command if more than 1 sec -function convertsecs() { +convertsecs() { ((d=${1}/3600/24)) ((h=${1}/3600%24)) ((m=(${1}%3600)/60)) @@ -115,10 +115,10 @@ function convertsecs() { printf " %ds" $s fi } -function preexec() { +preexec() { timer=${timer:-$SECONDS} } -function precmd() { +precmd() { if [ $timer ]; then timer_show=$(convertsecs $(($SECONDS - $timer))) export EXECTIME="${timer_show}" @@ -148,11 +148,11 @@ git_modified() { prompt_with_vimode() { - echo -ne '\n' - echo -n '%(1j.%{$fg[yellow]%}%jbg %{$reset_color%}.)' # background jobs - echo -n "$1" # strong for insert/normal mode - echo -n '%(!.%{$fg_bold[red]%}#.%{$fg[green]%}$)%{$reset_color%}' # su or norm - echo -n '%{$reset_color%} ' + echo -ne '\n' + echo -n '%(1j.%{$fg[yellow]%}%jbg %{$reset_color%}.)' # background jobs + echo -n "$1" + echo -n '%(!.%{$fg_bold[red]%}#.%{$fg[green]%}$)%{$reset_color%}' # su/norm + echo -n '%{$reset_color%} ' } insert_mode='' @@ -170,16 +170,17 @@ PROMPT=$(prompt_with_vimode $insert_mode) RPROMPT=$(rprompt) function zle-line-init zle-keymap-select { - PROMPT=$(prompt_with_vimode ${${KEYMAP/vicmd/$normal_mode}/(main|viins)/$insert_mode}) - RPROMPT=$(rprompt) - zle reset-prompt + PROMPT=$(prompt_with_vimode \ + ${${KEYMAP/vicmd/$normal_mode}/(main|viins)/$insert_mode}) + RPROMPT=$(rprompt) + zle reset-prompt } zle -N zle-line-init zle -N zle-keymap-select -# Plugins +#### PLUGINS export ZPLUG_HOME=~/code/zplug source $ZPLUG_HOME/init.zsh @@ -200,7 +201,7 @@ zplug load # start ssh-agent if [ -z "$SSH_AUTH_SOCK" ]; then - eval `ssh-agent` && ssh-add + eval `ssh-agent` && ssh-add fi > /dev/null 2>&1 # pass **<tab> @@ -213,13 +214,6 @@ _fzf_complete_pass() { sed -e 's/\(.*\)\.gpg/\1/' ) } -# redefine git log alias -alias gl="git log --graph --oneline --decorate --all --color=always | - fzf --ansi +s --preview='git show --color=always {2}' \ - --bind='pgdn:preview-page-down' \ - --bind='pgup:preview-page-up' \ - --bind='enter:execute:git show --color=always {2} | less -R' \ - --bind='ctrl-x:execute:git checkout {2} .'" . ~/.commands.sh . ~/.locale diff --git a/links/bin/tmux-utility.sh b/links/bin/tmux-utility.sh @@ -1,76 +1,70 @@ -#!/bin/sh +#!/bin/bash SESSION=utility echo "starting $SESSION tmux session" -tmux has-session -t $SESSION -if [ $? != 0 ] +if ! tmux has-session -t $SESSION then mpd ~/.mpd/mpd.conf - if [ "$(uname)" = "Darwin" ]; then - ssh-add -K - else - ssh-add - fi # Create new session, name it, name the window, detach tmux new-session -s $SESSION -n misc -d - tmux send-keys -t $SESSION 'echo $PWD' C-m - tmux send-keys -t $SESSION 'mutt' C-m + tmux send-keys -t $SESSION "echo $PWD" C-m + tmux send-keys -t $SESSION "mutt" C-m tmux split-window -h -t $SESSION - tmux send-keys -t $SESSION '~/bin/google-cloud-lamps-instance1-ssh.sh' C-m + tmux send-keys -t $SESSION "$HOME/bin/google-cloud-lamps-instance1-ssh.sh" C-m tmux select-pane -t $SESSION:1.1 tmux split-window -p 33 -v -t $SESSION - #tmux send-keys -t $SESSION 'fortune' C-m - tmux send-keys -t $SESSION '~/bin/todo.sh' C-m + #tmux send-keys -t $SESSION "fortune" C-m + tmux send-keys -t $SESSION "$HOME/bin/todo.sh" C-m tmux new-window -t $SESSION tmux select-pane -t $SESSION:2.1 - tmux send-keys -t $SESSION 'vimpc' C-m + tmux send-keys -t $SESSION "vimpc" C-m # optionally load additional windows if [ "$1" = "seaice" ]; then tmux new-window -t $SESSION -n Granular tmux select-pane -t $SESSION:3.1 - tmux send-keys -t $SESSION 'cd ~/code/Granular && vim' C-m + tmux send-keys -t $SESSION "cd ~/code/Granular && vim" C-m tmux split-window -p 33 -h -t $SESSION - tmux send-keys -t $SESSION 'cd ~/code/Granular && julia' C-m + tmux send-keys -t $SESSION "cd ~/code/Granular && julia" C-m tmux new-window -t $SESSION -n SeaIce-exp tmux select-pane -t $SESSION:4.1 - tmux send-keys -t $SESSION 'cd ~/code/SeaIce-experiments' C-m + tmux send-keys -t $SESSION "cd ~/code/SeaIce-experiments" C-m tmux split-window -p 33 -h -t $SESSION tmux send-keys -t $SESSION \ - 'cd ~/code/SeaIce-experiments && ~/bin/granular-status.sh' C-m + "cd ~/code/SeaIce-experiments && ~/bin/granular-status.sh" C-m tmux new-window -t $SESSION -n idkfa tmux select-pane -t $SESSION:5.1 - tmux send-keys -t $SESSION '~/bin/idkfa-ssh' C-m - #'sshfs ad@idkfa.ucsd.edu:/home/ad ~/idkfa && ~/bin/idkfa-ssh' C-m + tmux send-keys -t $SESSION "$HOME/bin/idkfa-ssh" C-m + #"sshfs ad@idkfa.ucsd.edu:/home/ad ~/idkfa && ~/bin/idkfa-ssh" C-m tmux new-window -t $SESSION -n james tmux select-pane -t $SESSION:6.1 tmux send-keys -t $SESSION \ - 'cd ~/articles/own/6-james/james-rev0 && git pull && make edit' + "cd ~/articles/own/6-james/james-rev0 && git pull && make edit" fi #tmux select-layout tiled tmux select-pane -t $SESSION:1.1 - #tmux send-keys -t $SESSION 'irc.sh' C-m # process in first pane + #tmux send-keys -t $SESSION "irc.sh" C-m # process in first pane #tmux split-window -h -p 65 -t $SESSION # horizontal split #tmux split-window -v -p 10 -t $SESSION # bottom right - #tmux send-keys -t $SESSION 'htop' C-m + #tmux send-keys -t $SESSION "htop" C-m #tmux select-pane -t $SESSION:1.1 # select first pane #tmux split-window -v -p 60 -t $SESSION # create a pane below first pane #tmux split-window -v -p 56 -t $SESSION # create a pane below first pane - #tmux send-keys -t $SESSION 'htop' C-m # process in third pane + #tmux send-keys -t $SESSION "htop" C-m # process in third pane #tmux split-window -v -p 75 -t $SESSION # create a pane below second pane - #tmux send-keys -t $SESSION 'irc.sh' C-m # process in fourth pane - #tmux send-keys -t $SESSION 'ncmpcpp' C-m # process in fourth pane - #tmux send-keys -t $SESSION 'mpd; vimpc' C-m # process in fourth pane + #tmux send-keys -t $SESSION "irc.sh" C-m # process in fourth pane + #tmux send-keys -t $SESSION "ncmpcpp" C-m # process in fourth pane + #tmux send-keys -t $SESSION "mpd; vimpc" C-m # process in fourth pane #tmux select-pane -t $SESSION:1.1 # select first pane fi tmux attach -t $SESSION