Skip to content

Instantly share code, notes, and snippets.

@spiralx
Last active July 13, 2021 04:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiralx/f277c595989549d8ef01 to your computer and use it in GitHub Desktop.
Save spiralx/f277c595989549d8ef01 to your computer and use it in GitHub Desktop.
Current Bash profile used by Git Bash
#!/bin/sh
source ~/shell/colours.sh
B1=" ${YELLOW} ♦ ${YELLOW}"
B2=" ${CYAN} ● ${WHITE}"
#B2=" ${BCYAN} ○ ${WHITE}"
echo
echo -e "${B1}Welcome ${BBLUE}${USERNAME}${YELLOW}!${RESET}"
echo -e " ------------------------"
# -----------------------------------------------------------------------------
# Shell configuration
shopt -s dotglob extglob nocaseglob nocasematch
# -----------------------------------------------------------------------------
# Exported variables
source ~/shell/exports.sh
# -----------------------------------------------------------------------------
# Aliases
source ~/shell/alias-global.sh
source ~/shell/alias-local.sh
echo -e "${B2}Aliases loaded${RESET}"
# -----------------------------------------------------------------------------
# Commands and other initialisation
source ~/shell/funcs.sh
source ~/shell/tput.sh
echo -e "${B2}Functions defined${RESET}"
source ~/shell/git-init.sh
echo -e "${B2}Git initialised${RESET}"
source ~/shell/npm-init.sh
echo -e "${B2}Node initialised${RESET}"
source ~/shell/ssh-init.sh
echo -e "${B2}SSH initialised${RESET}"
# source ~/shell/project.sh
# source ~/shell/bookmarks.sh
# -----------------------------------------------------------------------------
# Done!
echo -e "${B2}${BYELLOW}Executed .bashrc!${RESET}"
echo
# -----------------------------------------------------------------------------
# Aliases common to all environments
alias q='exit'
# Directory listings
alias ls='ls -FhLX --color'
alias ll='ls -o'
alias la='ll -a'
alias ld='ll | grep "^d"'
alias sl='ls'
# Aliases for cd - .. ... ....
alias -- -='cd -'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
# Other directory stuff
alias md='mkdir'
alias pu='pushd'
alias pop='popd'
# Shell-related commands
#alias env='env | sort'
alias h='history 50'
alias path='echo $PATH | tr : "\n" | grep -v "\." | sort | uniq -i'
alias unaliasall='unalias -a'
alias editconf='notepad ~/.bashrc'
alias loadconf='source ~/.bashrc'
# Jobs and processes
alias j='jobs -l'
alias p='pstree -p'
alias r='fc -s'
# File stuff
alias which='type'
alias egrep='grep -E'
alias fgrep='grep -F'
alias jsonpp='json_pp'
# Applications
alias serve='python -m http.server 9000'
#!/bin/sh
RS='\e[0m'
INV='\e[7m'
UNV='\e[27m'
# -----------------------------------------------------------------------------
# Escape commands
# Reset all colours and styles
RESET='\e[0m'
BOLD='\e[1m'
DIM='\e[2m'
STANDOUT='\e[2m'
UNDERLINE='\e[4m'
BLINK='\e[5m'
REVERSE_VIDEO='\e[7m'
CONCEALED='\e[7m'
NORMAL='\e[22m'
NO_STANDOUT='\e[23m'
NO_UNDERLINE='\e[24m'
NO_BLINK='\e[25m'
NO_REVERSE_VIDEO='\e[27m'
# -----------------------------------------------------------------------------
# Foreground colours
# Standard
BLACK='\e[0;30m' # Black
RED='\e[0;31m' # Red
GREEN='\e[0;32m' # Green
YELLOW='\e[0;33m' # Yellow
BLUE='\e[0;34m' # Blue
PURPLE='\e[0;35m' # Purple
CYAN='\e[0;36m' # Cyan
WHITE='\e[0;37m' # White
DEFAULT='\e[0;39m' # Default
# Bold
BBLACK='\e[1;30m' # Black
BRED='\e[1;31m' # Red
BGREEN='\e[1;32m' # Green
BYELLOW='\e[1;33m' # Yellow
BBLUE='\e[1;34m' # Blue
BPURPLE='\e[1;35m' # Purple
BCYAN='\e[1;36m' # Cyan
BWHITE='\e[1;37m' # White
# Underlined
UBLACK='\e[4;30m' # Black
URED='\e[4;31m' # Red
UGREEN='\e[4;32m' # Green
UYELLOW='\e[4;33m' # Yellow
UBLUE='\e[4;34m' # Blue
UPURPLE='\e[4;35m' # Purple
UCYAN='\e[4;36m' # Cyan
UWHITE='\e[4;37m' # White
# Blink?
LBLACK='\e[5;30m' # Black
LRED='\e[5;31m' # Red
LGREEN='\e[5;32m' # Green
LYELLOW='\e[5;33m' # Yellow
LBLUE='\e[5;34m' # Blue
LPURPLE='\e[5;35m' # Purple
LCYAN='\e[5;36m' # Cyan
LWHITE='\e[5;37m' # White
# High-intensity
IBLACK='\e[0;90m' # Black
IRED='\e[0;91m' # Red
IGREEN='\e[0;92m' # Green
IYELLOW='\e[0;93m' # Yellow
IBLUE='\e[0;94m' # Blue
IPURPLE='\e[0;95m' # Purple
ICYAN='\e[0;96m' # Cyan
IWHITE='\e[0;97m' # White
# High-intensity bold
BIBLACK='\e[1;90m' # Black
BIRED='\e[1;91m' # Red
BIGREEN='\e[1;92m' # Green
BIYELLOW='\e[1;93m' # Yellow
BIBLUE='\e[1;94m' # Blue
BIPURPLE='\e[1;95m' # Purple
BICYAN='\e[1;96m' # Cyan
BIWHITE='\e[1;97m' # White
# -----------------------------------------------------------------------------
# Background colours
ON_BLACK='\e[0;40m' # Black
ON_RED='\e[0;41m' # Red
ON_GREEN='\e[0;42m' # Green
ON_YELLOW='\e[0;43m' # Yellow
ON_BLUE='\e[0;44m' # Blue
ON_PURPLE='\e[0;45m' # Purple
ON_CYAN='\e[0;46m' # Cyan
ON_WHITE='\e[0;47m' # White
ON_DEFAULT='\e[0;49m' # Default
# Bold
ON_BBLACK='\e[5;40m' # Black
ON_BRED='\e[5;41m' # Red
ON_BGREEN='\e[5;42m' # Green
ON_BYELLOW='\e[5;43m' # Yellow
ON_BBLUE='\e[5;44m' # Blue
ON_BPURPLE='\e[5;45m' # Purple
ON_BCYAN='\e[5;46m' # Cyan
ON_BWHITE='\e[5;47m' # White
# High-intensity
ON_IBLACK='\e[0;100m' # Black
ON_IRED='\e[0;101m' # Red
ON_IGREEN='\e[0;102m' # Green
ON_IYELLOW='\e[0;103m' # Yellow
ON_IBLUE='\e[0;104m' # Blue
ON_IPURPLE='\e[0;105m' # Purple
ON_ICYAN='\e[0;106m' # Cyan
ON_IWHITE='\e[0;107m' # White
# High-intensity bold
ON_BIBLACK='\e[5;100m' # Black
ON_BIRED='\e[5;101m' # Red
ON_BIGREEN='\e[5;102m' # Green
ON_BIYELLOW='\e[5;103m' # Yellow
ON_BIBLUE='\e[5;104m' # Blue
ON_BIPURPLE='\e[5;105m' # Purple
ON_BICYAN='\e[5;106m' # Cyan
ON_BIWHITE='\e[5;107m' # White
# -----------------------------------------------------------------------------
# Foreground/background combinations
BLACK_ON_BLACK='\e[0;40;30m' # Black
BLACK_ON_RED='\e[0;41;30m' # Red
BLACK_ON_GREEN='\e[0;42;30m' # Green
BLACK_ON_YELLOW='\e[0;43;30m' # Yellow
BLACK_ON_BLUE='\e[0;44;30m' # Blue
BLACK_ON_PURPLE='\e[0;45;30m' # Purple
BLACK_ON_CYAN='\e[0;46;30m' # Cyan
BLACK_ON_WHITE='\e[0;47;30m' # White
BLACK_ON_DEFAULT='\e[0;49;30m' # Default
BLACK_ON_BBLACK='\e[5;40;30m' # Black
BLACK_ON_BRED='\e[5;41;30m' # Red
BLACK_ON_BGREEN='\e[5;42;30m' # Green
BLACK_ON_BYELLOW='\e[5;43;30m' # Yellow
BLACK_ON_BBLUE='\e[5;44;30m' # Blue
BLACK_ON_BPURPLE='\e[5;45;30m' # Purple
BLACK_ON_BCYAN='\e[5;46;30m' # Cyan
BLACK_ON_BWHITE='\e[5;47;30m' # White
BLACK_ON_BDEFAULT='\e[5;49;30m' # Default
BWHITE_ON_RED='\e[1;37;41m' # Red
BWHITE_ON_GREEN='\e[1;37;42m' # Green
BWHITE_ON_YELLOW='\e[1;37;43m' # Yellow
BWHITE_ON_BLUE='\e[1;37;44m' # Blue
BWHITE_ON_PURPLE='\e[1;37;45m' # Purple
BWHITE_ON_CYAN='\e[1;37;46m' # Cyan
BWHITE_ON_WHITE='\e[1;37;47m' # White
BWHITE_ON_DEFAULT='\e[1;37;49m' # Default
BWHITE_ON_BRED='\e[5;37;41m' # Red
BWHITE_ON_BGREEN='\e[5;37;42m' # Green
BWHITE_ON_BYELLOW='\e[5;37;43m' # Yellow
BWHITE_ON_BBLUE='\e[5;37;44m' # Blue
BWHITE_ON_BPURPLE='\e[5;37;45m' # Purple
BWHITE_ON_BCYAN='\e[5;37;46m' # Cyan
BWHITE_ON_BWHITE='\e[5;37;47m' # White
BWHITE_ON_BDEFAULT='\e[5;37;49m' # Default
# Black on white
INVERSE='\e[0;47;30m'
BINVERSE='\e[5;47;30m'
# -----------------------------------------------------------------------------
# Exported variables
export LS_OPTIONS='-FghLX --color=auto --group-directories-first'
# -d or --dumb
# -E or --QUIT-AT-EOF
# -I or --IGNORE-CASE
# -M or --LONG-PROMPT
# -S or --chop-long-lines
# -xn or --tabs=n
# -X or --no-init
export LESS='-EIX -x2'
# export PROMPT_COMMAND='ConEmuC -StoreCWD'
export NOTEPAD='/c/WINDOWS/System32/notepad'
export DEV_DIR='/c/dev'
export ETC_DIR='/c/Windows/System32/drivers/etc'
#export GIT_DIR='/c/Apps/Git'
export PYTHON_DIR='/c/Users/james/AppData/Local/Programs/Python/Python35/'
export PYTHON_SITE_DIR="${PYTHON_DIR}/lib/site-packages"
export SL_ROOT_DIR=`cygpath ${SEEDLEGALS_ROOT_DIR}`
export SL_PROJECT_DIR="${SL_ROOT_DIR}/seedlegals"
export SL_API_DIR="${SL_PROJECT_DIR}/src"
export SL_WEBAPP_DIR="${SL_PROJECT_DIR}/web"
export SL_DEPLOY_MSG='Web: Latest version compiled'
# -----------------------------------------------------------------------------
# If the first parameter doesn't contain %s, append it
#
# $ _gettmpl pre-%s-post
# pre-%s-post
#
# $ _gettmpl karma-
# karma-%s
#
function _gettmpl {
if [[ $1 != *"%s"* ]]; then
echo "${1}%s"
else
echo $1
fi
}
# -----------------------------------------------------------------------------
# Sort arguments
#
function sortargs {
printf "%s\n" "$@" | sort
}
# -----------------------------------------------------------------------------
# Join strings with optional format
#
# Joining a variable:
#
# $ plugins="mocha chai-plugins sinon webpack coverage spec-reporter"
# $ join $plugins
# mocha chai-plugins sinon webpack coverage spec-reporter
#
# Specifying a custom separator:
#
# $ join -s , $plugins
# mocha,chai-plugins,sinon,webpack,coverage,spec-reporter
#
# Joining arguments including strings:
#
# $ join -s ', ' foo bar baz 'moo MOO!'
# foo, bar, baz, moo MOO!
#
function join {
if [[ $1 == "-s" ]]; then
local sep="$2"
shift 2
else
local sep=" "
fi
echo "$1$(printf -- "$sep%s" "${@:2}")"
}
# -----------------------------------------------------------------------------
# Split string by delimiter, output selected fields
#
# Split on spaces
# $ echo foo bar 1.2 | split
# foo bar 1.2
#
# Select fields
# $ echo foo bar 1.2 | split -2
# foo bar
# $ echo foo bar 1.2 | split 2-
# bar 1.2
#
# Specify input delimiter
# $ echo foo,bar,1.2 | split ,
# foo bar 1.2
# $ echo 'foo|bar|1.2' | split 1-2 '|'
# foo bar
#
# Specify fields, input and output delimiters
# $ echo 'foo|bar|1.2' | split 2-3 '|' ', '
# bar, 1.2
#
function split {
#echo "($1)"
if [[ $1 =~ ^[0-9]*-[0-9]*$ ]]; then
local fields=$1
shift
else
local fields="1-"
fi
#echo $fields
cut --delimiter="${1-" "}" --output-delimiter="${2-" "}" --fields=$fields -
}
# -----------------------------------------------------------------------------
# Expand a template for one or more values inline...
#
# Expand items in an array variable:
#
# $ REPO_LIST=(browser-app samples resources)
# $ xp "http://git.example.com/%s.git" ${REPO_LIST[@]}
# http://git.example.com/browser-app.git http://git.example.com/samples.git http://git.example.com/resources.git
#
# Same result, but values passed as arguments:
#
# $ xp "http://git.example.com/%s.git" browser-app samples resources
# http://git.example.com/browser-app.git http://git.example.com/samples.git http://git.example.com/resources.git
#
# Using xp within a command:
#
# $ LOADERS=(style css babel html file)
# $ echo npm i --save-dev webpack $(xp "%s-loader" ${LOADERS[@]})
# npm i --save-dev webpack style-loader css-loader babel-loader html-loader file-loader
#
# Using a template without an explicit %s marker:
#
# $ xp karma- jasmine webpack coverage spec-reporter
# karma-jasmine karma-webpack karma-coverage karma-spec-reporter
#
function xp {
local tmpl=`_gettmpl "$1"`
shift
echo $(printf -- "$tmpl " ${*})
}
# -----------------------------------------------------------------------------
# Use a template to execute a command for one or more values...
#
# $ REPO_URL='https://git.magnolia-cms.com/scm/documentation'
#
# From an array variable:
#
# $ REPO_LIST=(fs-browser-app sample-resources template-tutorial using-resources)
# $ map "git clone ${REPO_URL}/%s.git" "${REPO_LIST[@]}"
#
# Values specified inline:
#
# $ map "git clone ${REPO_URL}/%s.git" fs-browser-app using-resources
#
function mapexec {
local tmpl=`_gettmpl "$1"`
shift
for val ; do
# echo "tmpl: $tmpl, val: $val, cmd: $(printf -- "$tmpl" "$val")"
eval $(printf "$tmpl" "$val")
done
}
# -----------------------------------------------------------------------------
# Show sorted environment variables with optional filter
#
# $ env
#
# Show environment variables with 'home' in the name (case-insensitive)
#
# $ env home
#
function env {
if [ $# -gt 0 ]; then
# /bin/env | grep -i "$*" | sort
while IFS='=' read -r -e k v; do
echo -e "${BYELLOW}${k}${RS}: ${CYAN}${v//\\/\\\\}${RS}"
done <<< $(/bin/env | grep -i "$*" | sort)
else
while IFS='=' read -r -e k v; do
echo -e "${BYELLOW}${k}${RS}: ${CYAN}${v//\\/\\\\}${RS}"
done <<< $(/bin/env | sort)
fi
}
# -----------------------------------------------------------------------------
# Display sorted, unique directories in the system path
#
# $ path
#
# To display in original form with duplicates:
#
# $ path -u
function path {
if [[ $1 == "-u" ]]; then
echo $PATH | tr : "\n" | grep -v "\."
else
echo $PATH | tr : "\n" | grep -v "\." | sort | uniq -i
fi
}
# -----------------------------------------------------------------------------
# Show file
#
# $ m ~/.bashrc
#
function m {
#arg1="$@" && [ -z "$arg1" ] && arg1="-"
local a=`[ $# = 0 ] && echo "-" || echo "$*"`
#echo "args: $a"
cat "$a" | less -FX
}
# -----------------------------------------------------------------------------
# Launch Notepad2
#
# $ e ./package.json
#
function e {
if [ $# -gt 0 ]; then
$NOTEPAD -n -q "$@" &
else
$NOTEPAD -n -q -s:js &
fi
}
# -----------------------------------------------------------------------------
# Edit file in Notepad
#
# $ ed ./package.json
#
function ed {
# echo ["${@}"]
if [ $# -gt 0 ] && [ -e "$1" ]; then
notepad -n -q "$1" &
else
notepad -n -q -s:js &
fi
}
# -----------------------------------------------------------------------------
# Open a URL in your browser
#
function open {
local url=${1-.}
$COMSPEC '\/S \/C start ${url}'
}
# -----------------------------------------------------------------------------
# Show help - 'h ls' is the same as 'ls --help'
#
function hh {
$(printf "%s --help" "${@}")
}
# -----------------------------------------------------------------------------
# Make a new directory and cd into it
#
function mcd {
mkdir -p "$1" && cd "$_"
}
# -----------------------------------------------------------------------------
# Highlight occurences of expression
#
function hili {
local e="$1"
shift
egrep --col=always -ih "$e|$" "$@"
}
# -----------------------------------------------------------------------------
# Dump an SQLLite3 database to SQL
#
# $ s3dump0 ./foobar.db > foobar.sql
#
function s3dump {
#map "sqlite3 -cmd .dump %s .quit > "${val}.sql"
for val ; do
sqlite3 -cmd .dump "${val}" .quit > "${val}.sql"
[ $? -eq 0 ] && echo Wrote "${val}.sql"
done
}
# -----------------------------------------------------------------------------
# Execute an XSLT transformation using Saxon
#
function xslt {
if [[ $# == 1 && $1 == "-h" ]]; then
open http://www.saxonica.com/html/documentation/using-xsl/commandline.html
else
local params="-jar /c/dev/Java/saxon-9.7.0/saxon9he.jar $1 $2"
exec java '$params'
fi
}
# -----------------------------------------------------------------------------
# Convert path from Windows to Bash format
#
function b2f {
if [ -t 0 ]; then
if [ $# -gt 0 ]; then
echo "$*" | sed -r 's/\\/\//g' | sed -r 's/^([A-Za-z]):/\/\l\1/' | sed -r 's/(\s)/\\\1/g'
fi
else
cat - | sed -r 's/\\/\//g' | sed -r 's/^([A-Za-z]):/\/\l\1/' | sed -r 's/(\s)/\\\1/g'
fi
}
# -----------------------------------------------------------------------------
# Dump a JSON file
#
function jsdump {
for val ; do
cat "${val}" | json -j > "${val}.json"
[ $? -eq 0 ] && echo Wrote "${val}.json"
done
}
source ~/shell/colours.sh
# -------------------------------------------------------------
# Configure command completion for Git repos and commands
source ~/shell/git-completion.sh
# -------------------------------------------------------------
# Colours and adds repository info to the prompt
source ~/shell/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=on
GIT_PS1_SHOWUPSTREAM=on
#GIT_PS1_SHOWCOLORHINTS=on
export PROMPT_COMMAND='__git_ps1 "\n${BGREEN}\u ${BCYAN}\w${BPURPLE}" " ${BRED}\\\$ ${RESET}"'
# -------------------------------------------------------------
# Git aliases and helper commands
alias ga='git add'
alias gd='git diff'
alias gs='git status'
alias gl='git ls'
alias git-ssh-test='ssh -T git@github.com'
# Git clone that understands GitHub
function gc {
if [[ $1 =~ https?:\/\/.+ ]]; then
git clone $*
elif [[ $1 == *"/"* ]]; then
git clone "https://github.com/$1" ${*:2}
else
git clone "https://github.com/spiralx/$1" ${*:2}
fi
}
function go {
local cur_branch=`git rev-parse --abbrev-ref HEAD`
local next_branch=${1:-$GIT_PREV_BRANCH}
if [ "$next_branch" != "" ]; then
git checkout $next_branch && export GIT_PREV_BRANCH=$cur_branch
fi
}
function gp {
git rev-parse --is-inside-work-tree > NUL || return
toplevel="`git rev-parse --show-toplevel`"
cd "/${toplevel/:/}"
}
#!/bin/sh
# bash/zsh git prompt support
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Distributed under the GNU General Public License, version 2.0.
#
# This script allows you to see repository status in your prompt.
#
# To enable:
#
# 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
# 2) Add the following line to your .bashrc/.zshrc:
# source ~/.git-prompt.sh
# 3a) Change your PS1 to call __git_ps1 as
# command-substitution:
# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
# ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
# the optional argument will be used as format string.
# 3b) Alternatively, for a slightly faster prompt, __git_ps1 can
# be used for PROMPT_COMMAND in Bash or for precmd() in Zsh
# with two parameters, <pre> and <post>, which are strings
# you would put in $PS1 before and after the status string
# generated by the git-prompt machinery. e.g.
# Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
# will show username, at-sign, host, colon, cwd, then
# various status string, followed by dollar and SP, as
# your prompt.
# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
# will show username, pipe, then various status string,
# followed by colon, cwd, dollar and SP, as your prompt.
# Optionally, you can supply a third argument with a printf
# format string to finetune the output of the branch status
#
# The repository status will be displayed only if you are currently in a
# git repository. The %s token is the placeholder for the shown status.
#
# The prompt status always includes the current branch name.
#
# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
# unstaged (*) and staged (+) changes will be shown next to the branch
# name. You can configure this per-repository with the
# bash.showDirtyState variable, which defaults to true once
# GIT_PS1_SHOWDIRTYSTATE is enabled.
#
# You can also see if currently something is stashed, by setting
# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
# then a '$' will be shown next to the branch name.
#
# If you would like to see if there're untracked files, then you can set
# GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
# files, then a '%' will be shown next to the branch name. You can
# configure this per-repository with the bash.showUntrackedFiles
# variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is
# enabled.
#
# If you would like to see the difference between HEAD and its upstream,
# set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates you are behind, ">"
# indicates you are ahead, "<>" indicates you have diverged and "="
# indicates that there is no difference. You can further control
# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list
# of values:
#
# verbose show number of commits ahead/behind (+/-) upstream
# name if verbose, then also show the upstream abbrev name
# legacy don't use the '--count' option available in recent
# versions of git-rev-list
# git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream
#
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
# find one, or @{upstream} otherwise. Once you have set
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
# setting the bash.showUpstream config variable.
#
# If you would like to see more information about the identity of
# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
# to one of these values:
#
# contains relative to newer annotated tag (v1.6.3.2~35)
# branch relative to newer tag or branch (master~4)
# describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
# default exactly matching tag
#
# If you would like a colored hint about the current dirty state, set
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
# the colored output of "git status -sb" and are available only when
# using __git_ps1 for PROMPT_COMMAND or precmd.
# check whether printf supports -v
__git_printf_supports_v=
printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
# stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM
__git_ps1_show_upstream ()
{
local key value
local svn_remote svn_url_pattern count n
local upstream=git legacy="" verbose="" name=""
svn_remote=()
# get some config options from git-config
local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
while read -r key value; do
case "$key" in
bash.showupstream)
GIT_PS1_SHOWUPSTREAM="$value"
if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
p=""
return
fi
;;
svn-remote.*.url)
svn_remote[$((${#svn_remote[@]} + 1))]="$value"
svn_url_pattern="$svn_url_pattern\\|$value"
upstream=svn+git # default upstream is SVN if available, else git
;;
esac
done <<< "$output"
# parse configuration values
for option in ${GIT_PS1_SHOWUPSTREAM}; do
case "$option" in
git|svn) upstream="$option" ;;
verbose) verbose=1 ;;
legacy) legacy=1 ;;
name) name=1 ;;
esac
done
# Find our upstream
case "$upstream" in
git) upstream="@{upstream}" ;;
svn*)
# get the upstream from the "git-svn-id: ..." in a commit message
# (git-svn uses essentially the same procedure internally)
local -a svn_upstream
svn_upstream=($(git log --first-parent -1 \
--grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
if [[ 0 -ne ${#svn_upstream[@]} ]]; then
svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
svn_upstream=${svn_upstream%@*}
local n_stop="${#svn_remote[@]}"
for ((n=1; n <= n_stop; n++)); do
svn_upstream=${svn_upstream#${svn_remote[$n]}}
done
if [[ -z "$svn_upstream" ]]; then
# default branch name for checkouts with no layout:
upstream=${GIT_SVN_ID:-git-svn}
else
upstream=${svn_upstream#/}
fi
elif [[ "svn+git" = "$upstream" ]]; then
upstream="@{upstream}"
fi
;;
esac
# Find how many commits we are ahead/behind our upstream
if [[ -z "$legacy" ]]; then
count="$(git rev-list --count --left-right \
"$upstream"...HEAD 2>/dev/null)"
else
# produce equivalent output to --count for older versions of git
local commits
if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
then
local commit behind=0 ahead=0
for commit in $commits
do
case "$commit" in
"<"*) ((behind++)) ;;
*) ((ahead++)) ;;
esac
done
count="$behind $ahead"
else
count=""
fi
fi
# calculate the result
if [[ -z "$verbose" ]]; then
case "$count" in
"") # no upstream
p="" ;;
"0 0") # equal to upstream
p="=" ;;
"0 "*) # ahead of upstream
p=">" ;;
*" 0") # behind upstream
p="<" ;;
*) # diverged from upstream
p="<>" ;;
esac
else
case "$count" in
"") # no upstream
p="" ;;
"0 0") # equal to upstream
p=" u=" ;;
"0 "*) # ahead of upstream
p=" u+${count#0 }" ;;
*" 0") # behind upstream
p=" u-${count% 0}" ;;
*) # diverged from upstream
p=" u+${count#* }-${count% *}" ;;
esac
if [[ -n "$count" && -n "$name" ]]; then
__git_ps1_upstream_name=$(git rev-parse \
--abbrev-ref "$upstream" 2>/dev/null)
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
p="$p \${__git_ps1_upstream_name}"
else
p="$p ${__git_ps1_upstream_name}"
# not needed anymore; keep user's
# environment clean
unset __git_ps1_upstream_name
fi
fi
fi
}
# Helper function that is meant to be called from __git_ps1. It
# injects color codes into the appropriate gitstring variables used
# to build a gitstring.
__git_ps1_colorize_gitstring ()
{
if [[ -n ${ZSH_VERSION-} ]]; then
local c_red='%F{red}'
local c_green='%F{green}'
local c_lblue='%F{blue}'
local c_clear='%f'
else
# Using \[ and \] around colors is necessary to prevent
# issues with command line editing/browsing/completion!
local c_red='\[\e[31m\]'
local c_green='\[\e[32m\]'
local c_lblue='\[\e[1;34m\]'
local c_clear='\[\e[0m\]'
fi
local bad_color=$c_red
local ok_color=$c_green
local flags_color="$c_lblue"
local branch_color=""
if [ $detached = no ]; then
branch_color="$ok_color"
else
branch_color="$bad_color"
fi
c="$branch_color$c"
z="$c_clear$z"
if [ "$w" = "*" ]; then
w="$bad_color$w"
fi
if [ -n "$i" ]; then
i="$ok_color$i"
fi
if [ -n "$s" ]; then
s="$flags_color$s"
fi
if [ -n "$u" ]; then
u="$bad_color$u"
fi
r="$c_clear$r"
}
__git_eread ()
{
f="$1"
shift
test -r "$f" && read "$@" <"$f"
}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# when called from PS1 using command substitution
# in this mode it prints text to add to bash PS1 prompt (includes branch name)
#
# __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc)
# in that case it _sets_ PS1. The arguments are parts of a PS1 string.
# when two arguments are given, the first is prepended and the second appended
# to the state string when assigned to PS1.
# The optional third parameter will be used as printf format string to further
# customize the output of the git-status string.
# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
__git_ps1 ()
{
local pcmode=no
local detached=no
local ps1pc_start='\u@\h:\w '
local ps1pc_end='\$ '
local printf_format=' (%s)'
case "$#" in
2|3) pcmode=yes
ps1pc_start="$1"
ps1pc_end="$2"
printf_format="${3:-$printf_format}"
;;
0|1) printf_format="${1:-$printf_format}"
;;
*) return
;;
esac
# ps1_expanded: This variable is set to 'yes' if the shell
# subjects the value of PS1 to parameter expansion:
#
# * bash does unless the promptvars option is disabled
# * zsh does not unless the PROMPT_SUBST option is set
# * POSIX shells always do
#
# If the shell would expand the contents of PS1 when drawing
# the prompt, a raw ref name must not be included in PS1.
# This protects the user from arbitrary code execution via
# specially crafted ref names. For example, a ref named
# 'refs/heads/$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' might cause the
# shell to execute 'sudo rm -rf /' when the prompt is drawn.
#
# Instead, the ref name should be placed in a separate global
# variable (in the __git_ps1_* namespace to avoid colliding
# with the user's environment) and that variable should be
# referenced from PS1. For example:
#
# __git_ps1_foo=$(do_something_to_get_ref_name)
# PS1="...stuff...\${__git_ps1_foo}...stuff..."
#
# If the shell does not expand the contents of PS1, the raw
# ref name must be included in PS1.
#
# The value of this variable is only relevant when in pcmode.
#
# Assume that the shell follows the POSIX specification and
# expands PS1 unless determined otherwise. (This is more
# likely to be correct if the user has a non-bash, non-zsh
# shell and safer than the alternative if the assumption is
# incorrect.)
#
local ps1_expanded=yes
[ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
[ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no
local repo_info rev_parse_exit_code
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
--is-bare-repository --is-inside-work-tree \
--short HEAD 2>/dev/null)"
rev_parse_exit_code="$?"
if [ -z "$repo_info" ]; then
if [ $pcmode = yes ]; then
#In PC mode PS1 always needs to be set
PS1="$ps1pc_start$ps1pc_end"
fi
return
fi
local short_sha
if [ "$rev_parse_exit_code" = "0" ]; then
short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
fi
local inside_worktree="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local bare_repo="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local inside_gitdir="${repo_info##*$'\n'}"
local g="${repo_info%$'\n'*}"
local r=""
local b=""
local step=""
local total=""
if [ -d "$g/rebase-merge" ]; then
__git_eread "$g/rebase-merge/head-name" b
__git_eread "$g/rebase-merge/msgnum" step
__git_eread "$g/rebase-merge/end" total
if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
else
r="|REBASE-m"
fi
else
if [ -d "$g/rebase-apply" ]; then
__git_eread "$g/rebase-apply/next" step
__git_eread "$g/rebase-apply/last" total
if [ -f "$g/rebase-apply/rebasing" ]; then
__git_eread "$g/rebase-apply/head-name" b
r="|REBASE"
elif [ -f "$g/rebase-apply/applying" ]; then
r="|AM"
else
r="|AM/REBASE"
fi
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
r="|CHERRY-PICKING"
elif [ -f "$g/REVERT_HEAD" ]; then
r="|REVERTING"
elif [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
if [ -n "$b" ]; then
:
elif [ -h "$g/HEAD" ]; then
# symlink symbolic ref
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
local head=""
if ! __git_eread "$g/HEAD" head; then
if [ $pcmode = yes ]; then
PS1="$ps1pc_start$ps1pc_end"
fi
return
fi
# is it a symbolic ref?
b="${head#ref: }"
if [ "$head" = "$b" ]; then
detached=yes
b="$(
case "${GIT_PS1_DESCRIBE_STYLE-}" in
(contains)
git describe --contains HEAD ;;
(branch)
git describe --contains --all HEAD ;;
(describe)
git describe HEAD ;;
(* | default)
git describe --tags --exact-match HEAD ;;
esac 2>/dev/null)" ||
b="$short_sha..."
b="($b)"
fi
fi
fi
if [ -n "$step" ] && [ -n "$total" ]; then
r="$r $step/$total"
fi
local w=""
local i=""
local s=""
local u=""
local c=""
local p=""
if [ "true" = "$inside_gitdir" ]; then
if [ "true" = "$bare_repo" ]; then
c="BARE:"
else
b="GIT_DIR!"
fi
elif [ "true" = "$inside_worktree" ]; then
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
[ "$(git config --bool bash.showDirtyState)" != "false" ]
then
git diff --no-ext-diff --quiet --exit-code || w="*"
if [ -n "$short_sha" ]; then
git diff-index --cached --quiet HEAD -- || i="+"
else
i="#"
fi
fi
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
[ -r "$g/refs/stash" ]; then
s="$"
fi
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
then
u="%${ZSH_VERSION+%}"
fi
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
__git_ps1_show_upstream
fi
fi
local z="${GIT_PS1_STATESEPARATOR-" "}"
# NO color option unless in PROMPT_COMMAND mode
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
__git_ps1_colorize_gitstring
fi
b=${b##refs/heads/}
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
__git_ps1_branch_name=$b
b="\${__git_ps1_branch_name}"
fi
local f="$w$i$s$u"
local gitstring="$c$b${f:+$z$f}$r$p"
if [ $pcmode = yes ]; then
if [ "${__git_printf_supports_v-}" != yes ]; then
gitstring=$(printf -- "$printf_format" "$gitstring")
else
printf -v gitstring -- "$printf_format" "$gitstring"
fi
PS1="$ps1pc_start$gitstring$ps1pc_end"
else
printf -- "$printf_format" "$gitstring"
fi
}
#!/bin/bash
function mtree {
mvn dependency:tree -Dverbose=true -Dincludes=info.magnolia*:::,com.bcsg*::: > dependency-tree.txt
e dependency-tree.txt
}
function mpurge {
mvn dependency:purge-local-repository -Dverbose=true -Dincludes=info.magnolia*:::,com.bcsg*:::
}
function mpurgeall {
mvn dependency:purge-local-repository -Dverbose=true
}
alias mi='mvn -e -X -Dmaven.test.skip=true install'
alias mr='mvn -f darwin-webapp/pom.xml jetty:run'
alias mir='mvn -e -X -Dmaven.test.skip=true install && mvn -f darwin-webapp/pom.xml jetty:run'
alias mcir='mvn -e -X -Dmaven.test.skip=true -U -Dmaven.clean.failOnError=false clean install && mvn -f darwin-webapp/pom.xml jetty:run'
#!/bin/bash
###-begin-npm-completion-###
#
# npm command completion script
#
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
#
if type complete &>/dev/null; then
_npm_completion () {
local words cword
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref -n = -n @ -w words -i cword
else
cword="$COMP_CWORD"
words=("${COMP_WORDS[@]}")
fi
local si="$IFS"
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
complete -o default -F _npm_completion npm
elif type compdef &>/dev/null; then
_npm_completion() {
local si=$IFS
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
npm completion -- "${words[@]}" \
2>/dev/null)
IFS=$si
}
compdef _npm_completion npm
elif type compctl &>/dev/null; then
_npm_completion () {
local cword line point words si
read -Ac words
read -cn cword
let cword-=1
read -l line
read -ln point
si="$IFS"
IFS=$'\n' reply=($(COMP_CWORD="$cword" \
COMP_LINE="$line" \
COMP_POINT="$point" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
compctl -K _npm_completion npm
fi
###-end-npm-completion-###
# -----------------------------------------------------------------------------
# Node initialisation
NODE_OPTIONS="array_prototype_values async_await do_expressions for_in regexp_lookbehind regexp_named_captures regexp_property string_padding trailing_commas"
alias n="node --log_colour --harmony $(xp "--harmony_" "${NODE_OPTIONS[@]}")"
function npminstallmulti {
npm i --save-dev $(join "${@}")
}
source ~/shell/npm-completion.sh
# -----------------------------------------------------------------------------
# Start SSH
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent ..."
# spawn ssh-agent
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo "... succeeded"
echo "-----"
cat "${SSH_ENV}"
echo "-----"
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add
}
if [ -f "${SSH_ENV}" ]; then
echo "Found existing environment file, executing ..."
echo "-----"
cat "${SSH_ENV}"
echo "-----"
. "${SSH_ENV}" > /dev/null
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
echo "... ssh-agent process not found, restarting!"
start_agent;
}
else
echo "No environment file found!"
start_agent;
fi
#!/bin/sh
# -----------------------------------------------------------------------------
# Shim for the `tput` command that's missing in Git Bash on Windows. See
# here for a full list of capabilities `tput` implements:
#
# https://www.gnu.org/software/termutils/manual/termutils-2.0/html_chapter/tput_1.html
#
# This command lists all properties extracted from `cmd.exe`:
#
# $COMSPEC //C mode con | sed '1,3d;9d' | sed -r 's/.*([A-Z][^:]+):\s+([0-9]+)$/"\1" = \2/g'
BLK_ON_RED="\e[0;41;30m"
RESET="\e[0m"
function getProperty {
$COMSPEC //C mode con | grep -i "$1" | sed -r 's/.*([A-Z][^:]+):\s+([0-9]+)$/\2/g'
}
function tput {
case "$1" in
clear) $COMSPEC //C cls ;;
cols) getProperty Columns | getValue ;;
lines) echo 40 ;;
lm) getProperty Lines | getValue ;;
cup) echo "cup ${2}, ${3}" ;;
smso) echo -en "\e[0;1;7m" ;;
bold) echo -en "\e[1m" ;;
dim) echo -en "\e[2m" ;;
smul) echo -en "\e[4m" ;;
rmul) echo -en "\e[24m" ;;
"rev") echo -en "\e[0;7m" ;;
setb | setab) echo -en "\e[4"${2}"m" ;;
setf | setaf) echo -en "\e[3"${2}"m" ;;
rmso | sgr0) echo -en "\e[0m" ;;
*)
echo "${BLK_ON_RED}Unknown tput command '$1'!${RESET}"
exit 1
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment