commit 151f95e1b93f70ebc4d2babde6344895beedf39a
parent ad53dc111642ba1cbffe2fb7b2985fdd7ab1dd28
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 30 May 2018 09:58:33 -0400
Make .commands.sh universal
Diffstat:
6 files changed, 60 insertions(+), 157 deletions(-)
diff --git a/links/.bash_profile b/links/.bash_profile
@@ -1,85 +1,3 @@
-#### LOCALE
-
-export LC_ALL=en_US.UTF-8
-export LANG=en_US.UTF-8
-
-[ -f $HOME/.secret_env_vars ] && source $HOME/.secret_env_vars
-
-
-#### PATH AND MACHINE SPECIFIC CONFIGS
-
-[ -d /usr/local/bin ] && export PATH=/usr/local/bin:$PATH
-[ -d /usr/local/sbin ] && export PATH=/usr/local/sbin:$PATH
-[ -d $HOME/local/bin ] && export PATH=$HOME/local/bin:$PATH
-[ -d $HOME/bin ] && export PATH=$HOME/bin:$PATH
-if [ -d $HOME/.linuxbrew ]; then
- export PATH=$HOME/.linuxbrew/bin:$PATH
- export MANPATH=$HOME/.linuxbrew/share/man:$MANPATH
- export INFOPATH=$HOME/.linuxbrew/share/info:$INFOPATH
-fi
-if [ -d /home/linuxbrew/.linuxbrew ]; then
- export PATH=/home/linuxbrew/.linuxbrew/bin:$PATH
- export MANPATH=/home/linuxbrew/.linuxbrew/share/man:$MANPATH
- export INFOPATH=/home/linuxbrew/.linuxbrew/share/info:$INFOPATH
-fi
-
-#if [ -d $HOME/local/python ]; then
-# export PYTHONPATH=$HOME/local/python:$PYTHONPATH
-# export PATH=$HOME/local/python:$PATH
-#fi
-
-if [ $(echo $HOSTNAME | grep flaptop) ]; then
- #source ~/.xsh
- #export PATH=~/miniconda3/bin:$PATH
- export PATH=/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:$PATH
-fi
-
-if [ $(echo $HOSTNAME | grep cosmo) ]; then
- export PATH=/usr/local/MATLAB/R2015a/bin:$PATH
-fi
-
-export GOPATH=$HOME/src/golang
-export PATH=$PATH:$GOPATH/bin
-export GPG_TTY=`tty`
-
-[ -d $HOME/pism ] && export PATH=$HOME/pism/bin:$PATH
-[ -d ~/code/issm/trunk ] && export ISSM_DIR=~/code/issm/trunk
-[ -d ~/torch/install/bin ] && export PATH=~/torch/install/bin:$PATH
-[ -d ~/code/tensorflow ] && alias tensorflow='source ~/code/tensorflow/bin/activate'
-
-if _has fzf; then
-
- export FZF_DEFAULT_OPTS="
- --preview '(highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null | head -100'
- "
-
- # fzf can be launched with ctrl-t or alt-c
- export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
- export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND"
-
- # use ripgrep if available
- if _has rg; then
- # --files: List files that would be searched but do not search
- # --no-ignore: Do not respect .gitignore, etc...
- # --hidden: Search hidden files and folders
- # --follow: Follow symlinks
- # --glob: (in this case ignore everything in the .git/ folder)
- export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --glob "!.git/*"'
-
- # use the_silver_searcher if available
- elif _has ag; then
- export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -f --nocolor -g ""'
- fi
-fi
-
-if [ -f /usr/local/Modules/default/init/zsh ]; then
- source /usr/local/Modules/default/init/zsh && \
- #module load git vim #python paraview ncview matlab ifort anaconda
- module load git python/2.7.1
- [ -d /net/and/anaconda3/bin ] && export PATH="/net/and/anaconda3/bin:$PATH"
- [ -d /work/and/anaconda3/bin ] && export PATH="/work/and/anaconda3/bin:$PATH"
-fi
-[ -f /etc/pki/tls/certs/ca-bundle.crt ] && export CURL_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt
-
-[ -d ~/code/basilisk/src ] && export BASILISK=~/code/basilisk/src
-[ -d ~/code/basilisk/src ] && export PATH=~/code/basilisk/src:$PATH
+#!/bin/bash
+. ~/.profile
+[ -f ~/.bashrc ] && . ~/.bashrc
diff --git a/links/.bashrc b/links/.bashrc
@@ -17,8 +17,6 @@ HISTFILESIZE=20000
_has() {
return $( type -v "$1" &> /dev/null )
}
-# shellcheck source=/Users/ad/.bash_profile
-[ -f ~/.bash_profile ] && source ~/.bash_profile
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
@@ -27,6 +25,14 @@ shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
+export CLICOLOR=1
+export HISTTIMEFORMAT='%F %T '
+export EDITOR=vim
+GPG_TTY=$(tty)
+export GPG_TTY
+
+. ~/.commands.sh
+
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
@@ -55,28 +61,6 @@ else
fi
unset color_prompt force_color_prompt
-# Useful aliases
-alias ll='ls -alF'
-alias la='ls -A'
-alias l='ls -CF'
-alias vi='vim -u NONE'
-#alias ls='ls $LS_OPTIONS -hF'
-alias play='mpg123 --title -C'
-# Set bash title for certain terminals
-#echo -n -e "\033]0;`hostname`\007"
-ARCH=$(uname)
-if [[ "$ARCH" != 'Darwin' ]]; then
- function open() { xdg-open "$1" &> /dev/null &disown; }
- function say() { echo "$@" | festival --tts; }
-fi
-
# shellcheck source=/Users/ad/.fzf.bash
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
-# Dircolors
-export CLICOLOR=1
-
-export HISTTIMEFORMAT='%F %T '
-export EDITOR=vim
-GPG_TTY=$(tty)
-export GPG_TTY
diff --git a/links/.commands.sh b/links/.commands.sh
@@ -1,32 +1,24 @@
-#!/usr/bin/env zsh
+#!/bin/bash
#### FUNCTIONS AND ALIASES
-if [[ "$(uname)" != 'Darwin' ]]; then
- function open() { xdg-open $1 &> /dev/null &disown; }
- function say() { echo "$@" | festival --tts; }
+if [ "$(uname)" != 'Darwin' ]; then
+ open() { xdg-open "$@" &> /dev/null &disown; }
+ 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 {
+sayfile() { festival --tts "$@"; }
+w3mtor() {
local url
if [ $# -eq 0 ]; then
url="https://check.torproject.org/"
else
url=$1
fi
- torify w3m $url
+ 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 {
+w3mddg() { torify surfraw ddg "$@"; }
+weather() { curl "wttr.in/?m"; }
+define() { curl --silent dict://dict.org/d:"$1"; }
+news() {
local url
if [ $# -eq 0 ]; then
url="https://text.npr.org"
@@ -37,12 +29,12 @@ function news {
else
url=$1
fi
- torify w3m $url
+ torify w3m "$url"
}
# Start emacs daemon if it is not running, then attach client
-function e () {
- if [ ! $(pgrep emacs --daemon) ]; then
+e() {
+ if [ ! "$(pgrep emacs --daemon)" ]; then
echo starting emacs daemon
emacsdaemonlog=~/.emacs-daemon.log
[ -f ~/.emacs-daemon.log ] && rm $emacsdaemonlog # delete old logfile
@@ -51,20 +43,22 @@ function e () {
emacsclient -t
}
-function transfer() { # use transfer.sh to share files over the net
+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"
+ echo -e "No arguments specified. Usage: transfer.sh <file>"
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
+ curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" \
+ >> "$tmpfile"
else
- curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile
+ curl --progress-bar --upload-file "-" "https://transfer.sh/$1" \
+ >> "$tmpfile"
fi
- cat $tmpfile
- rm -f $tmpfile
+ cat "$tmpfile"
+ rm -f "$tmpfile"
echo ""
}
@@ -103,7 +97,6 @@ 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'
@@ -115,14 +108,11 @@ 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/.bash_profile b/links/.profile
diff --git a/links/.zprofile b/links/.zprofile
@@ -0,0 +1,3 @@
+#!/usr/bin/env zsh
+
+. ~/.profile
diff --git a/links/.zshrc b/links/.zshrc
@@ -1,8 +1,4 @@
#### ZSH PERFORMANCE DEBUG (enable all)
-# setopt prompt_subst
-# zmodload zsh/datetime
-# PS4='+[$EPOCHREALTIME]%N:%i> '
-# set -x
debug_startup=false
[ "$debug_startup" = true ] && zmodload zsh/zprof
@@ -14,8 +10,7 @@ _has() {
return $( (( $+commands[$1] )) )
}
-[ -f ~/.bash_profile ] && source ~/.bash_profile
-[ -f $HOME/.locale ] && $HOME/.locale
+[ -f ~/.locale ] && . ~/.locale
autoload -Uz compinit promptinit colors
compinit -d
@@ -23,17 +18,17 @@ promptinit
colors
set -o noclobber # prevent overwriting files with > (override with 1>)
-unset AUTO_CD
-setopt CORRECT
+unsetopt autocd
+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))
+HISTFILE=~/.zsh-history
+HISTSIZE=$((2 ** 16))
+SAVEHIST=$((2 ** 17))
#### ZSH APPEARANCE
@@ -65,6 +60,7 @@ function precmd() {
fi
}
+# show git information
function git_branch() {
branch_name=$(git symbolic-ref --short HEAD 2> /dev/null)
if [ -n "$branch_name" ]; then
@@ -83,13 +79,19 @@ function git_modified() {
}
# check for background jobs
-local bg_jobs="%(1j.%{$fg[yellow]%}%j%{$fg[blue]%}bg %{$reset_color%}.)"
-local return_status="%(?..%{$fg[red]%}%?%{$reset_color%})"
-local prompt_root="%(!.%{$fg_bold[red]%}#.%{$fg[green]%}$)%{$reset_color%}"
+bg_jobs="%(1j.%{$fg[yellow]%}%jbg %{$reset_color%}.)"
+# show return status of previous command
+return_status="%(?..%{$fg[red]%}%?%{$reset_color%})"
+
+# change prompt according to su
+prompt_root="%(!.%{$fg_bold[red]%}#.%{$fg[green]%}$)%{$reset_color%}"
+
+# define left prompt format
PROMPT="
${bg_jobs}%{$fg[red]%}${prompt_root} %{$reset_color%}"
+# define right prompt format
RPROMPT="${return_status}\
${EXECTIME}\
%{$fg[green]%}${EXECTIME}%{$reset_color%} \
@@ -162,7 +164,7 @@ bindkey '^g' _editor_fuzzy_grep
#### FUNCTIONS AND ALIASES
-source ~/.commands.sh
+. ~/.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
@@ -179,7 +181,7 @@ done
# zgen is faster than zplug
if [ -f ~/code/zgen/zgen.zsh ]; then
- source ~/code/zgen/zgen.zsh
+ . ~/code/zgen/zgen.zsh
if ! zgen saved; then
@@ -219,4 +221,10 @@ if _has fzf; then
--bind='ctrl-x:execute:git checkout {2} .'"
fi
+#### Extra options
+
+# show directory listing when changing dir
+function chpwd() { ls }
+
+
[ "$debug_startup" = true ] && zprof || :