| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- CYAN="\e[96m"
- GREEN="\e[92m"
- RED="\e[91m"
- BBLUE="\e[34;1m"
- RESET="\e[0m"
- IS_PASS() {
- [[ $1 -eq 0 ]] || [[ $1 -gt 128 ]]
- }
- SUCCESS() {
- if IS_PASS $1; then
- echo -en $GREEN
- else
- echo -en $RED
- fi
- }
- CODE() { IS_PASS $1 || echo "(rc=$1) "; }
- GITBRANCH() {
- local branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
- if [[ -z ${branch} ]]; then return; fi
- if [[ ${branch} == "HEAD" ]]; then
- echo -n ":$(git show -s --format=%h)"
- else
- echo -n ":${branch}"
- fi
- }
- export PS1='$(rc=$?; echo -e "\[$CYAN\]\D{%F %T} \[$BBLUE\]\u\[$RESET\]@\[$(SUCCESS $rc)\]\h:[\w$(GITBRANCH)] $(CODE $rc)\[$RESET\]$ ")'
- export EDITOR=nvim
- PATH="$HOME/usr/local/bin:$HOME/bin:$HOME/usr/bin:$PATH"
- export PATH
- export LC_ALL=en_US.UTF-8
- if [[ -z "$BASEPATH" ]]; then
- export BASEPATH="$PATH"
- fi
- alias reset-path="export PATH=\"$BASEPATH\""
- # Turn a number of symlink files into copies of their original
- # Usage:
- # detach file...
- detach() {
- for i; do [ -L "$i" ] && cp --remove-destination $(readlink "$i") "$i"; done
- }
- link-tools() {
- PATH=$HOME/tools/bin:$HOME/tools/usr/bin:$PATH
- LD_LIBRARY_PATH=$HOME/tools/lib:$HOME/tools/usr/lib:$LD_LIBRARY_PATH
- export PATH
- export LD_LIBRARY_PATH
- }
- unlink-tools() {
- PATH=$(echo $PATH | perl -pne "s/(?<=:)$HOME/tools.*?://g")
- LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | perl -pne "s/(?<=:)$HOME/tools.*?://g")
- export PATH
- export LD_LIBRARY_PATH
- }
- alias listall="list -A"
- alias disk-usage="ls -A | xargs du -shc | sort -h"
- alias reload="source ~/.bashrc"
- alias crontab="VIM_CRONTAB=true crontab"
- refreshterm() {
- clear
- uname -a
- cat /etc/motd
- echo ""
- pwd
- list
- }
- _mkcd_fun() {
- if [ ! -d "$2" ]; then
- if [ -e "$2" ]; then
- echo "mkcd: file exists and is not a directory"
- exit
- else
- $1 "$2"
- fi
- fi
- cd "$2"
- }
- alias mkcd="_mkcd_fun mkdir"
- mkdirs() {
- mkdir -p "$1"
- }
- alias mkcds="_mkcd_fun mkdirs"
- alias diffr="diff --ignore-blank-lines --minimal --side-by-side --report-identical-files --suppress-common-lines"
- alias diffl="diff --changed-group-format='%<' --unchanged-group-format=''"
- _recall_fun() {
- if [ -z "$1" ]; then echo "recall: usage: recall string"; return 1; fi
- history | cut -c 8- | grep --extended-regexp "$1" | \
- grep --invert-match --extended-regexp "^(history|recall|redo)" | sort | uniq
- }
- redo() {
- IFS=$'\n'
- hist=($(_recall_fun $1))
- for ((i=0; i<${#hist[@]}; i++));
- do
- echo "[$i] ${hist[$i]}"
- done
- printf "Index: "
- read idx
- if [[ $idx =~ ^[0-9]+$ ]];
- then
- eval "${hist[$idx]}"
- fi
- unset IFS
- }
- recall(){
- _recall_fun $1 | sed 's/^/ /'
- }
- clear() {
- /usr/bin/clear
- if [[ ! -z "${TMUX}" ]]; then tmux clear-history; fi
- }
- swap() {
- if [[ $# -ne 2 ]]; then
- echo "swap file1 file2" >&2
- return 1
- fi
- local tmpfile=$(mktemp)
- mv "${1}" "${tmpfile}"
- mv "${2}" "${1}"
- mv "${tmpfile}" "${2}"
- }
- has() {
- [[ "$(type -t "${1}")" =~ function|alias|file ]]
- }
- maybe_do() {
- has "${1}" && "$@"
- }
- alias coms="${HOME}/tools/comstore/commands.sh"
- clrun() {
- clear
- echo "$@"
- "$@"
- }
- _total_on_bottom() {
- local cap=""
- while read line; do
- if [[ ${line} =~ .*total$ ]]; then
- local cap="${line}"
- else
- echo "${line}"
- fi
- done
- if [[ -n "${cap}" ]]; then
- echo "${cap}"
- fi
- }
- _rlall_noself() {
- for i in "$@"; do
- [[ $(basename ${i}) =~ ^\.\.?$ ]] || readlink -f "${i}"
- done
- }
- dus() {
- if [[ ${1} == "-a" ]]; then
- IFS=$'\n' args=($(_rlall_noself "${2}/"* "${2}/".* )); unset IFS
- elif [[ ${1} == "-d" ]]; then
- IFS=$'\n' args=($(_rlall_noself "${2}/"* )); unset IFS
- else
- IFS=$'\n' args=($(_rlall_noself "$@")); unset IFS
- fi
- du -shc "${args[@]}" | sort -h | _total_on_bottom
- }
- repeat() {
- local n=$1
- shift
- for ((i=0;i<n;++i)); do
- "$@"
- done
- }
- scriptdiff() {
- vimdiff <("${@:3}" "$1") <("${@:3}" "$2")
- }
- vimdiff_jq() {
- scriptdiff "$2" "$3" jq -M "$1"
- }
- if [[ $(uname) == "Darwin" ]]; then # OSX
- . ${HOME}/.profile-osx
- elif [[ $(uname) == *BSD* ]]; then # FreeBSD
- . ${HOME}/.profile-bsd
- else
- . ${HOME}/.profile-linux
- fi
- . ${HOME}/.profile-dev
- has git && . ${HOME}/.profile-git || true
- has p4 && . ${HOME}/.profile-p4 || true
|