add bash-it
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# shellcheck shell=bash
|
||||
# stub for renamed file
|
||||
|
||||
_enable-completion aliases && _disable-plugin alias-completion
|
||||
source "${BASH_IT?}/completion/available/aliases.completion.bash"
|
||||
14
dot_bash_it/plugins/available/autojump.plugin.bash
Normal file
14
dot_bash_it/plugins/available/autojump.plugin.bash
Normal file
@@ -0,0 +1,14 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Autojump configuration, see https://github.com/wting/autojump for more details'
|
||||
|
||||
# Only supports the Homebrew variant, Debian and Arch at the moment.
|
||||
# Feel free to provide a PR to support other install locations
|
||||
# shellcheck disable=SC1090
|
||||
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then
|
||||
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh"
|
||||
elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then
|
||||
source "$(dpkg-query -S autojump.sh | cut -d' ' -f2)"
|
||||
elif _command_exists pacman && pacman -Q autojump &> /dev/null; then
|
||||
source "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)"
|
||||
fi
|
||||
113
dot_bash_it/plugins/available/aws.plugin.bash
Normal file
113
dot_bash_it/plugins/available/aws.plugin.bash
Normal file
@@ -0,0 +1,113 @@
|
||||
cite about-plugin
|
||||
about-plugin 'AWS helper functions'
|
||||
|
||||
AWS_CONFIG_FILE="${AWS_CONFIG_FILE:-$HOME/.aws/config}"
|
||||
AWS_SHARED_CREDENTIALS_FILE="${AWS_SHARED_CREDENTIALS_FILE:-$HOME/.aws/credentials}"
|
||||
|
||||
function awskeys {
|
||||
about 'helper function for AWS credentials file'
|
||||
group 'aws'
|
||||
|
||||
if [[ ! -f "${AWS_SHARED_CREDENTIALS_FILE}" ]]; then
|
||||
echo "AWS credentials file not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $# -eq 1 ]] && [[ "$1" = "list" ]]; then
|
||||
__awskeys_list "$2"
|
||||
elif [[ $# -eq 1 ]] && [[ "$1" = "unset" ]]; then
|
||||
__awskeys_unset "$2"
|
||||
elif [[ $# -eq 2 ]] && [[ "$1" = "show" ]]; then
|
||||
__awskeys_show "$2"
|
||||
elif [[ $# -eq 2 ]] && [[ "$1" = "export" ]]; then
|
||||
__awskeys_export "$2"
|
||||
else
|
||||
__awskeys_help
|
||||
fi
|
||||
}
|
||||
|
||||
function __awskeys_help {
|
||||
echo -e "Usage: awskeys [COMMAND] [profile]\n"
|
||||
echo -e "Helper to AWS credentials file.\n"
|
||||
echo -e "Commands:\n"
|
||||
echo " help Show this help message"
|
||||
echo " list List available AWS credentials profiles"
|
||||
echo " show Show the AWS keys associated to a credentials profile"
|
||||
echo " export Export an AWS credentials profile keys as environment variables"
|
||||
echo " unset Unset the AWS keys variables from the environment"
|
||||
}
|
||||
|
||||
function __awskeys_get {
|
||||
local ln=$(grep -n "\[ *$1 *\]" "${AWS_SHARED_CREDENTIALS_FILE}" | cut -d ":" -f 1)
|
||||
if [[ -n "${ln}" ]]; then
|
||||
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | egrep -m 2 "aws_access_key_id|aws_secret_access_key"
|
||||
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | egrep -m 1 "aws_session_token"
|
||||
fi
|
||||
}
|
||||
|
||||
function __awskeys_list {
|
||||
local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"; grep "\[profile" "${AWS_CONFIG_FILE}" | sed "s|\[profile |\[|g") | sort | uniq)"
|
||||
if [[ -n $"{credentials_list}" ]]; then
|
||||
echo -e "Available credentials profiles:\n"
|
||||
for profile in ${credentials_list}; do
|
||||
echo " $(echo ${profile} | tr -d "[]")"
|
||||
done
|
||||
echo
|
||||
else
|
||||
echo "No profiles found in credentials file"
|
||||
fi
|
||||
}
|
||||
|
||||
function __awskeys_show {
|
||||
local p_keys="$(__awskeys_get $1)"
|
||||
if [[ -n "${p_keys}" ]]; then
|
||||
echo "${p_keys}"
|
||||
else
|
||||
echo "Profile $1 not found in credentials file"
|
||||
fi
|
||||
}
|
||||
|
||||
function __awskeys_export {
|
||||
if [[ $(__awskeys_list) == *"$1"* ]]; then
|
||||
local p_keys=( $(__awskeys_get $1 | tr -d " ") )
|
||||
if [[ -n "${p_keys}" ]]; then
|
||||
for p_key in ${p_keys[@]}; do
|
||||
local key="${p_key%=*}"
|
||||
export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}"
|
||||
done
|
||||
fi
|
||||
export AWS_PROFILE="$1"
|
||||
else
|
||||
echo "Profile $1 not found in credentials file"
|
||||
fi
|
||||
}
|
||||
|
||||
function __awskeys_unset {
|
||||
unset AWS_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
|
||||
}
|
||||
|
||||
function __awskeys_comp {
|
||||
local cur prev opts prevprev
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
opts="help list show export unset"
|
||||
|
||||
case "${prev}" in
|
||||
help|list|unset)
|
||||
return 0
|
||||
;;
|
||||
show|export)
|
||||
local profile_list="$(__awskeys_list | grep " ")"
|
||||
COMPREPLY=( $(compgen -W "${profile_list}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
complete -F __awskeys_comp awskeys
|
||||
185
dot_bash_it/plugins/available/base.plugin.bash
Normal file
185
dot_bash_it/plugins/available/base.plugin.bash
Normal file
@@ -0,0 +1,185 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'miscellaneous tools'
|
||||
|
||||
function ips() {
|
||||
about 'display all ip addresses for this host'
|
||||
group 'base'
|
||||
if _command_exists ifconfig; then
|
||||
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
|
||||
elif _command_exists ip; then
|
||||
ip addr | grep -oP 'inet \K[\d.]+'
|
||||
else
|
||||
echo "You don't have ifconfig or ip command installed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function down4me() {
|
||||
about 'checks whether a website is down for you, or everybody'
|
||||
param '1: website url'
|
||||
example '$ down4me http://www.google.com'
|
||||
group 'base'
|
||||
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
||||
}
|
||||
|
||||
function myip() {
|
||||
about 'displays your ip address, as seen by the Internet'
|
||||
group 'base'
|
||||
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
|
||||
for url in "${list[@]}"; do
|
||||
if res="$(curl -fs "${url}")"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
res="$(echo "$res" | grep -Eo '[0-9\.]+')"
|
||||
echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}"
|
||||
}
|
||||
|
||||
function pickfrom() {
|
||||
about 'picks random line from file'
|
||||
param '1: filename'
|
||||
example '$ pickfrom /usr/share/dict/words'
|
||||
group 'base'
|
||||
local file=${1:-}
|
||||
local -i n=0 length
|
||||
if [[ ! -r "$file" ]]; then
|
||||
reference "${FUNCNAME[0]}" && return
|
||||
fi
|
||||
length="$(wc -l < "$file")"
|
||||
n=$((RANDOM * length / 32768 + 1))
|
||||
head -n "$n" "$file" | tail -1
|
||||
}
|
||||
|
||||
function passgen() {
|
||||
about 'generates random password from dictionary words'
|
||||
param 'optional integer length'
|
||||
param 'if unset, defaults to 4'
|
||||
example '$ passgen'
|
||||
example '$ passgen 6'
|
||||
group 'base'
|
||||
local -i i length=${1:-4}
|
||||
local pass
|
||||
# shellcheck disable=SC2034
|
||||
pass="$(for i in $(eval "echo {1..$length}"); do pickfrom /usr/share/dict/words; done)"
|
||||
echo "With spaces (easier to memorize): ${pass//$'\n'/ }"
|
||||
echo "Without spaces (easier to brute force): ${pass//$'\n'/}"
|
||||
}
|
||||
|
||||
# Create alias pass to passgen when pass isn't installed or
|
||||
# BASH_IT_LEGACY_PASS is true.
|
||||
if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" == true ]]; then
|
||||
alias pass=passgen
|
||||
fi
|
||||
|
||||
if _command_exists markdown && _command_exists browser; then
|
||||
function pmdown() {
|
||||
about 'preview markdown file in a browser'
|
||||
param '1: markdown file'
|
||||
example '$ pmdown README.md'
|
||||
group 'base'
|
||||
|
||||
markdown "${1?}" | browser
|
||||
}
|
||||
fi
|
||||
|
||||
function mkcd() {
|
||||
about 'make one or more directories and cd into the last one'
|
||||
param 'one or more directories to create'
|
||||
example '$ mkcd foo'
|
||||
example '$ mkcd /tmp/img/photos/large'
|
||||
example '$ mkcd foo foo1 foo2 fooN'
|
||||
example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing'
|
||||
group 'base'
|
||||
mkdir -p -- "$@" && cd -- "${!#}" || return
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2010
|
||||
function lsgrep() {
|
||||
about 'search through directory contents with grep'
|
||||
group 'base'
|
||||
ls | grep "$@"
|
||||
}
|
||||
|
||||
function quiet() {
|
||||
about 'what *does* this do?'
|
||||
group 'base'
|
||||
nohup "$@" &> /dev/null < /dev/null &
|
||||
}
|
||||
|
||||
function usage() {
|
||||
about 'disk usage per directory, in Mac OS X and Linux'
|
||||
param '1: directory name'
|
||||
group 'base'
|
||||
case $OSTYPE in
|
||||
*'darwin'*)
|
||||
du -hd 1 "$@"
|
||||
;;
|
||||
*'linux'*)
|
||||
du -h --max-depth=1 "$@"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function t() {
|
||||
about 'todo.sh if available, otherwise one thing todo'
|
||||
param 'if not set, display todo item'
|
||||
param '1: todo text'
|
||||
|
||||
local todotxt="${XDG_STATE_HOME:-~/.local/state}/bash_it/todo.txt"
|
||||
|
||||
if _bash-it-component-item-is-enabled plugin todo; then
|
||||
todo.sh "$@"
|
||||
return
|
||||
elif [[ ! -f "${todotxt}" && -f ~/.t ]]; then
|
||||
mv -vn ~/.t "${todotxt}" # Verbose, so the user knows. Don't overwrite, just in case.
|
||||
fi
|
||||
|
||||
if [[ "$#" -eq 0 ]]; then
|
||||
cat "${todotxt}"
|
||||
else
|
||||
echo "$@" >| "${todotxt}"
|
||||
fi
|
||||
}
|
||||
|
||||
if _command_exists mkisofs; then
|
||||
function mkiso() {
|
||||
about 'creates iso from current dir in the parent dir (unless defined)'
|
||||
param '1: ISO name'
|
||||
param '2: dest/path'
|
||||
param '3: src/path'
|
||||
example 'mkiso'
|
||||
example 'mkiso ISO-Name dest/path src/path'
|
||||
group 'base'
|
||||
|
||||
local isoname="${1:-${PWD##*/}}"
|
||||
local destpath="${2:-../}"
|
||||
local srcpath="${3:-${PWD}}"
|
||||
|
||||
if [[ ! -f "${destpath%/}/${isoname}.iso" ]]; then
|
||||
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
|
||||
mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath%/}/${isoname}.iso" "${srcpath}"
|
||||
else
|
||||
echo "${destpath%/}/${isoname}.iso already exists"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# useful for administrators and configs
|
||||
function buf() {
|
||||
about 'back up file with timestamp'
|
||||
param 'filename'
|
||||
group 'base'
|
||||
local filename="${1?}" filetime
|
||||
filetime=$(date +%Y%m%d_%H%M%S)
|
||||
cp -a "${filename}" "${filename}_${filetime}"
|
||||
}
|
||||
|
||||
if ! _command_exists del; then
|
||||
function del() {
|
||||
about 'move files to hidden folder in tmp, that gets cleared on each reboot'
|
||||
param 'file or folder to be deleted'
|
||||
example 'del ./file.txt'
|
||||
group 'base'
|
||||
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash
|
||||
}
|
||||
fi
|
||||
16
dot_bash_it/plugins/available/basher.plugin.bash
Normal file
16
dot_bash_it/plugins/available/basher.plugin.bash
Normal file
@@ -0,0 +1,16 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'initializes basher, the shell package manager'
|
||||
|
||||
# https://github.com/basherpm/basher
|
||||
|
||||
if ! _command_exists basher; then
|
||||
if [[ -x "$HOME/.basher/bin/basher" ]]; then
|
||||
pathmunge "$HOME/.basher/bin"
|
||||
else
|
||||
_log_warning 'basher not found'
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
eval "$(basher init - bash)"
|
||||
130
dot_bash_it/plugins/available/battery.plugin.bash
Normal file
130
dot_bash_it/plugins/available/battery.plugin.bash
Normal file
@@ -0,0 +1,130 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'display info about your battery charge level'
|
||||
|
||||
function ac_adapter_connected() {
|
||||
local batteries
|
||||
if _command_exists upower; then
|
||||
IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
|
||||
upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'charging\|fully-charged'
|
||||
elif _command_exists acpi; then
|
||||
acpi -a | grep -q "on-line"
|
||||
elif _command_exists pmset; then
|
||||
pmset -g batt | grep -q 'AC Power'
|
||||
elif _command_exists ioreg; then
|
||||
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
|
||||
elif _command_exists WMIC; then
|
||||
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2'
|
||||
fi
|
||||
}
|
||||
|
||||
function ac_adapter_disconnected() {
|
||||
local batteries
|
||||
if _command_exists upower; then
|
||||
IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
|
||||
upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'discharging'
|
||||
elif _command_exists acpi; then
|
||||
acpi -a | grep -q "off-line"
|
||||
elif _command_exists pmset; then
|
||||
pmset -g batt | grep -q 'Battery Power'
|
||||
elif _command_exists ioreg; then
|
||||
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
|
||||
elif _command_exists WMIC; then
|
||||
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1'
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_percentage() {
|
||||
about 'displays battery charge as a percentage of full (100%)'
|
||||
group 'battery'
|
||||
|
||||
local command_output batteries
|
||||
|
||||
if _command_exists upower; then
|
||||
IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
|
||||
command_output="$(upower --show-info "${batteries[0]:-}" | grep percentage | grep -o '[0-9]\+' | head -1)"
|
||||
elif _command_exists acpi; then
|
||||
command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}')
|
||||
elif _command_exists pmset; then
|
||||
command_output=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o '[0-9]\+' | head -1)
|
||||
elif _command_exists ioreg; then
|
||||
command_output=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o '[0-9]\+' | head -1)
|
||||
elif _command_exists WMIC; then
|
||||
command_output=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
|
||||
else
|
||||
command_output="no"
|
||||
fi
|
||||
|
||||
if [[ "${command_output}" != "no" ]]; then
|
||||
printf "%02d" "${command_output:--1}"
|
||||
else
|
||||
echo "${command_output}"
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_charge() {
|
||||
about 'graphical display of your battery charge'
|
||||
group 'battery'
|
||||
|
||||
# Full char
|
||||
local f_c='▸'
|
||||
# Depleted char
|
||||
local d_c='▹'
|
||||
local depleted_color="${normal?}"
|
||||
local full_color="${green?}"
|
||||
local half_color="${yellow?}"
|
||||
local danger_color="${red?}"
|
||||
#local battery_output="${depleted_color}${d_c}${d_c}${d_c}${d_c}${d_c}"
|
||||
local battery_percentage
|
||||
battery_percentage=$(battery_percentage)
|
||||
|
||||
case $battery_percentage in
|
||||
no)
|
||||
echo ""
|
||||
;;
|
||||
9*)
|
||||
echo "${full_color}${f_c}${f_c}${f_c}${f_c}${f_c}${normal?}"
|
||||
;;
|
||||
8*)
|
||||
echo "${full_color}${f_c}${f_c}${f_c}${f_c}${half_color}${f_c}${normal?}"
|
||||
;;
|
||||
7*)
|
||||
echo "${full_color}${f_c}${f_c}${f_c}${f_c}${depleted_color}${d_c}${normal?}"
|
||||
;;
|
||||
6*)
|
||||
echo "${full_color}${f_c}${f_c}${f_c}${half_color}${f_c}${depleted_color}${d_c}${normal?}"
|
||||
;;
|
||||
5*)
|
||||
echo "${full_color}${f_c}${f_c}${f_c}${depleted_color}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
4*)
|
||||
echo "${full_color}${f_c}${f_c}${half_color}${f_c}${depleted_color}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
3*)
|
||||
echo "${full_color}${f_c}${f_c}${depleted_color}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
2*)
|
||||
echo "${full_color}${f_c}${half_color}${f_c}${depleted_color}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
1*)
|
||||
echo "${full_color}${f_c}${depleted_color}${d_c}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
05)
|
||||
echo "${danger_color}${f_c}${depleted_color}${d_c}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
04)
|
||||
echo "${danger_color}${f_c}${depleted_color}${d_c}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
03)
|
||||
echo "${danger_color}${f_c}${depleted_color}${d_c}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
02)
|
||||
echo "${danger_color}${f_c}${depleted_color}${d_c}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
0*)
|
||||
echo "${half_color}${f_c}${depleted_color}${d_c}${d_c}${d_c}${d_c}${normal?}"
|
||||
;;
|
||||
*)
|
||||
echo "${danger_color}UNPLG${normal?}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
19
dot_bash_it/plugins/available/blesh.plugin.bash
Normal file
19
dot_bash_it/plugins/available/blesh.plugin.bash
Normal file
@@ -0,0 +1,19 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load ble.sh, the Bash line editor!'
|
||||
|
||||
if [[ ${BLE_VERSION-} ]]; then
|
||||
_log_warning "ble.sh is already loaded!"
|
||||
return
|
||||
fi
|
||||
|
||||
_bash_it_ble_path=${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh
|
||||
if [[ -f $_bash_it_ble_path ]]; then
|
||||
# shellcheck disable=1090
|
||||
source "$_bash_it_ble_path" --attach=prompt
|
||||
else
|
||||
_log_error "Could not find ble.sh in $_bash_it_ble_path"
|
||||
_log_error "Please install using the following command:"
|
||||
_log_error "git clone https://github.com/akinomyoga/ble.sh && make -C ble.sh install"
|
||||
fi
|
||||
unset _bash_it_ble_path
|
||||
10
dot_bash_it/plugins/available/boot2docker.plugin.bash
Normal file
10
dot_bash_it/plugins/available/boot2docker.plugin.bash
Normal file
@@ -0,0 +1,10 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Helpers to get Docker setup correctly for boot2docker'
|
||||
|
||||
# Note, this might need to be different if you have an older version
|
||||
# of boot2docker, or its configured for a different IP
|
||||
if [[ "$OSTYPE" == 'darwin'* ]]; then
|
||||
export DOCKER_HOST="tcp://192.168.59.103:2376"
|
||||
export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm"
|
||||
export DOCKER_TLS_VERIFY=1
|
||||
fi
|
||||
76
dot_bash_it/plugins/available/browser.plugin.bash
Normal file
76
dot_bash_it/plugins/available/browser.plugin.bash
Normal file
@@ -0,0 +1,76 @@
|
||||
# based on https://gist.github.com/318247
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'render commandline output in your browser'
|
||||
|
||||
function browser() {
|
||||
about 'pipe html to a browser'
|
||||
example '$ echo "<h1>hi mom!</h1>" | browser'
|
||||
example '$ ron -5 man/rip.5.ron | browser'
|
||||
group 'browser'
|
||||
|
||||
if [ -t 0 ]; then
|
||||
if [ -n "$1" ]; then
|
||||
open $1
|
||||
else
|
||||
reference browser
|
||||
fi
|
||||
|
||||
else
|
||||
f="/tmp/browser.$RANDOM.html"
|
||||
cat /dev/stdin > $f
|
||||
open $f
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function wmate() {
|
||||
about 'pipe hot spicy interwebs into textmate and cleanup!'
|
||||
example '$ wmate google.com'
|
||||
group 'browser'
|
||||
|
||||
if [ -t 0 ]; then
|
||||
if [ -n "$1" ]; then
|
||||
wget -qO- $1 | /usr/bin/mate
|
||||
|
||||
TIDY=`/usr/bin/osascript << EOT
|
||||
tell application "TextMate"
|
||||
activate
|
||||
end tell
|
||||
|
||||
tell application "System Events"
|
||||
tell process "TextMate"
|
||||
tell menu bar 1
|
||||
tell menu bar item "Bundles"
|
||||
tell menu "Bundles"
|
||||
tell menu item "HTML"
|
||||
tell menu "HTML"
|
||||
click menu item "Tidy"
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
EOT`
|
||||
|
||||
else
|
||||
reference wmate
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function raw() {
|
||||
about 'write wget into a temp file and pump it into your browser'
|
||||
example '$ raw google.com'
|
||||
group 'browser'
|
||||
|
||||
if [ -t 0 ]; then
|
||||
if [ -n "$1" ]; then
|
||||
wget -qO- $1 | browser
|
||||
else
|
||||
reference raw
|
||||
fi
|
||||
fi
|
||||
}
|
||||
5
dot_bash_it/plugins/available/chruby-auto.plugin.bash
Normal file
5
dot_bash_it/plugins/available/chruby-auto.plugin.bash
Normal file
@@ -0,0 +1,5 @@
|
||||
cite about-plugin
|
||||
about-plugin 'load chruby + auto-switching (from /usr/local/share/chruby)'
|
||||
|
||||
source /usr/local/share/chruby/chruby.sh
|
||||
source /usr/local/share/chruby/auto.sh
|
||||
4
dot_bash_it/plugins/available/chruby.plugin.bash
Normal file
4
dot_bash_it/plugins/available/chruby.plugin.bash
Normal file
@@ -0,0 +1,4 @@
|
||||
cite about-plugin
|
||||
about-plugin 'load chruby (from /usr/local/share/chruby)'
|
||||
|
||||
source /usr/local/share/chruby/chruby.sh
|
||||
21
dot_bash_it/plugins/available/cht-sh.plugin.bash
Normal file
21
dot_bash_it/plugins/available/cht-sh.plugin.bash
Normal file
@@ -0,0 +1,21 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Simplify `curl cht.sh/<query>` to `cht.sh <query>`'
|
||||
|
||||
# Play nicely if user already installed cht.sh cli tool
|
||||
if ! _command_exists cht.sh ; then
|
||||
function cht.sh () {
|
||||
about 'Executes a cht.sh curl query using the provided arguments'
|
||||
param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]'
|
||||
example '$ cht.sh :help'
|
||||
example '$ cht.sh :list'
|
||||
example '$ cht.sh tar'
|
||||
example '$ cht.sh js "parse json"'
|
||||
example '$ cht.sh python :learn'
|
||||
example '$ cht.sh rust :list'
|
||||
group 'cht-sh'
|
||||
|
||||
# Separate arguments with '/', preserving spaces within them
|
||||
local query=$(IFS=/ ; echo "$*")
|
||||
curl "cht.sh/${query}"
|
||||
}
|
||||
fi
|
||||
@@ -0,0 +1,16 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
|
||||
|
||||
function precmd_return_notification() {
|
||||
local command_start="${COMMAND_DURATION_START_SECONDS:=0}"
|
||||
local current_time="${EPOCHREALTIME:-$SECONDS}"
|
||||
local -i command_duration="$((${current_time%.*} - ${command_start%.*}))"
|
||||
if [[ "${command_duration}" -gt "${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5}" ]]; then
|
||||
printf '\a'
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
safe_append_prompt_command 'precmd_return_notification'
|
||||
safe_append_preexec '_command_duration_pre_exec'
|
||||
197
dot_bash_it/plugins/available/colors.plugin.bash
Normal file
197
dot_bash_it/plugins/available/colors.plugin.bash
Normal file
@@ -0,0 +1,197 @@
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2005
|
||||
|
||||
function __() {
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
function __make_ansi() {
|
||||
next=$1
|
||||
shift
|
||||
echo "\[\e[$("__$next" "$@")m\]"
|
||||
}
|
||||
|
||||
function __make_echo() {
|
||||
next=$1
|
||||
shift
|
||||
echo "\033[$("__$next" "$@")m"
|
||||
}
|
||||
|
||||
function __reset() {
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "0${out:+;${out}}"
|
||||
}
|
||||
|
||||
function __bold() {
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "${out:+${out};}1"
|
||||
}
|
||||
|
||||
function __faint() {
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "${out:+${out};}2"
|
||||
}
|
||||
|
||||
function __italic() {
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "${out:+${out};}3"
|
||||
}
|
||||
|
||||
function __underline() {
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "${out:+${out};}4"
|
||||
}
|
||||
|
||||
function __negative() {
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "${out:+${out};}7"
|
||||
}
|
||||
|
||||
function __crossed() {
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "${out:+${out};}8"
|
||||
}
|
||||
|
||||
function __color_normal_fg() {
|
||||
echo "3$1"
|
||||
}
|
||||
|
||||
function __color_normal_bg() {
|
||||
echo "4$1"
|
||||
}
|
||||
|
||||
function __color_bright_fg() {
|
||||
echo "9$1"
|
||||
}
|
||||
|
||||
function __color_bright_bg() {
|
||||
echo "10$1"
|
||||
}
|
||||
|
||||
function __color_black() {
|
||||
echo "0"
|
||||
}
|
||||
|
||||
function __color_red() {
|
||||
echo "1"
|
||||
}
|
||||
|
||||
function __color_green() {
|
||||
echo "2"
|
||||
}
|
||||
|
||||
function __color_yellow() {
|
||||
echo "3"
|
||||
}
|
||||
|
||||
function __color_blue() {
|
||||
echo "4"
|
||||
}
|
||||
|
||||
function __color_magenta() {
|
||||
echo "5"
|
||||
}
|
||||
|
||||
function __color_cyan() {
|
||||
echo "6"
|
||||
}
|
||||
|
||||
function __color_white() {
|
||||
echo "7"
|
||||
}
|
||||
|
||||
function __color_rgb() {
|
||||
r=$1 && g=$2 && b=$3
|
||||
[[ $r == "$g" && $g == "$b" ]] && echo $((r / 11 + 232)) && return # gray range above 232
|
||||
echo "8;5;$(((r * 36 + b * 6 + g) / 51 + 16))"
|
||||
}
|
||||
|
||||
function __color() {
|
||||
color="$1"
|
||||
shift
|
||||
case "$1" in
|
||||
fg | bg)
|
||||
side="$1"
|
||||
shift
|
||||
;;
|
||||
*) side="fg" ;;
|
||||
esac
|
||||
case "$1" in
|
||||
normal | bright)
|
||||
mode="$1"
|
||||
shift
|
||||
;;
|
||||
*) mode=normal ;;
|
||||
esac
|
||||
[[ $color == "rgb" ]] && rgb="$1 $2 $3"
|
||||
shift 3
|
||||
|
||||
next=$1
|
||||
shift
|
||||
out="$("__$next" "$@")"
|
||||
echo "$("__color_${mode}_${side}" "$("__color_${color}" "$rgb")")${out:+;${out}}"
|
||||
}
|
||||
|
||||
function __black() {
|
||||
echo "$(__color black "$@")"
|
||||
}
|
||||
|
||||
function __red() {
|
||||
echo "$(__color red "$@")"
|
||||
}
|
||||
|
||||
function __green() {
|
||||
echo "$(__color green "$@")"
|
||||
}
|
||||
|
||||
function __yellow() {
|
||||
echo "$(__color yellow "$@")"
|
||||
}
|
||||
|
||||
function __blue() {
|
||||
echo "$(__color blue "$@")"
|
||||
}
|
||||
|
||||
function __magenta() {
|
||||
echo "$(__color magenta "$@")"
|
||||
}
|
||||
|
||||
function __cyan() {
|
||||
echo "$(__color cyan "$@")"
|
||||
}
|
||||
|
||||
function __white() {
|
||||
echo "$(__color white "$@")"
|
||||
}
|
||||
|
||||
function __rgb() {
|
||||
echo "$(__color rgb "$@")"
|
||||
}
|
||||
|
||||
function __color_parse() {
|
||||
next=$1
|
||||
shift
|
||||
echo "$("__$next" "$@")"
|
||||
}
|
||||
|
||||
function color() {
|
||||
echo "$(__color_parse make_ansi "$@")"
|
||||
}
|
||||
|
||||
function echo_color() {
|
||||
echo "$(__color_parse make_echo "$@")"
|
||||
}
|
||||
7
dot_bash_it/plugins/available/direnv.plugin.bash
Normal file
7
dot_bash_it/plugins/available/direnv.plugin.bash
Normal file
@@ -0,0 +1,7 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load direnv, if you are using it: https://direnv.net/'
|
||||
|
||||
if _command_exists direnv; then
|
||||
eval "$(direnv hook bash)"
|
||||
fi
|
||||
119
dot_bash_it/plugins/available/dirs.plugin.bash
Normal file
119
dot_bash_it/plugins/available/dirs.plugin.bash
Normal file
@@ -0,0 +1,119 @@
|
||||
# shellcheck shell=bash
|
||||
# Directory stack navigation:
|
||||
#
|
||||
# Add to stack with: pu /path/to/directory
|
||||
# Delete current dir from stack with: po
|
||||
# Show stack with: d
|
||||
# Jump to location by number.
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'directory stack navigation'
|
||||
|
||||
# Show directory stack
|
||||
alias d="dirs -v -l"
|
||||
|
||||
# Change to location in stack by number
|
||||
alias 1="pushd"
|
||||
alias 2="pushd +2"
|
||||
alias 3="pushd +3"
|
||||
alias 4="pushd +4"
|
||||
alias 5="pushd +5"
|
||||
alias 6="pushd +6"
|
||||
alias 7="pushd +7"
|
||||
alias 8="pushd +8"
|
||||
alias 9="pushd +9"
|
||||
|
||||
# Clone this location
|
||||
alias pc='pushd "${PWD}"'
|
||||
|
||||
# Push new location
|
||||
alias pu="pushd"
|
||||
|
||||
# Pop current location
|
||||
alias po="popd"
|
||||
|
||||
function dirs-help() {
|
||||
about 'directory navigation alias usage'
|
||||
group 'dirs'
|
||||
|
||||
echo "Directory Navigation Alias Usage"
|
||||
echo
|
||||
echo "Use the power of directory stacking to move"
|
||||
echo "between several locations with ease."
|
||||
echo
|
||||
echo "d : Show directory stack."
|
||||
echo "po : Remove current location from stack."
|
||||
echo "pc : Adds current location to stack."
|
||||
echo "pu <dir>: Adds given location to stack."
|
||||
echo "1 : Change to stack location 1."
|
||||
echo "2 : Change to stack location 2."
|
||||
echo "3 : Change to stack location 3."
|
||||
echo "4 : Change to stack location 4."
|
||||
echo "5 : Change to stack location 5."
|
||||
echo "6 : Change to stack location 6."
|
||||
echo "7 : Change to stack location 7."
|
||||
echo "8 : Change to stack location 8."
|
||||
echo "9 : Change to stack location 9."
|
||||
}
|
||||
|
||||
# Add bookmarking functionality
|
||||
# Usage:
|
||||
|
||||
: "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-${HOME}/.local/state}/bash_it/dirs}"
|
||||
if [[ -f "${BASH_IT_DIRS_BKS?}" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT_DIRS_BKS?}"
|
||||
elif [[ -f ~/.dirs ]]; then
|
||||
mv -vn ~/.dirs "${BASH_IT_DIRS_BKS?}"
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT_DIRS_BKS?}"
|
||||
else
|
||||
touch "${BASH_IT_DIRS_BKS?}"
|
||||
fi
|
||||
|
||||
alias L='cat "${BASH_IT_DIRS_BKS?}"'
|
||||
|
||||
# Goes to destination dir, otherwise stay in the dir
|
||||
function G() {
|
||||
about 'goes to destination dir'
|
||||
param '1: directory'
|
||||
example '$ G ..'
|
||||
group 'dirs'
|
||||
|
||||
cd "${1:-${PWD}}" || return
|
||||
}
|
||||
|
||||
function S() {
|
||||
about 'save a bookmark'
|
||||
param '1: bookmark name'
|
||||
example '$ S mybkmrk'
|
||||
group 'dirs'
|
||||
|
||||
[[ $# -eq 1 ]] || {
|
||||
echo "${FUNCNAME[0]} function requires 1 argument"
|
||||
return 1
|
||||
}
|
||||
|
||||
sed "/$1/d" "${BASH_IT_DIRS_BKS?}" > "${BASH_IT_DIRS_BKS?}.new"
|
||||
command mv "${BASH_IT_DIRS_BKS?}.new" "${BASH_IT_DIRS_BKS?}"
|
||||
echo "$1"=\""${PWD}"\" >> "${BASH_IT_DIRS_BKS?}"
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT_DIRS_BKS?}"
|
||||
}
|
||||
|
||||
function R() {
|
||||
about 'remove a bookmark'
|
||||
param '1: bookmark name'
|
||||
example '$ R mybkmrk'
|
||||
group 'dirs'
|
||||
|
||||
[[ $# -eq 1 ]] || {
|
||||
echo "${FUNCNAME[0]} function requires 1 argument"
|
||||
return 1
|
||||
}
|
||||
|
||||
sed "/$1/d" "${BASH_IT_DIRS_BKS?}" > "${BASH_IT_DIRS_BKS?}.new"
|
||||
command mv "${BASH_IT_DIRS_BKS?}.new" "${BASH_IT_DIRS_BKS?}"
|
||||
}
|
||||
|
||||
alias U='source "${BASH_IT_DIRS_BKS?}"' # Update bookmark stack
|
||||
20
dot_bash_it/plugins/available/docker-compose.plugin.bash
Normal file
20
dot_bash_it/plugins/available/docker-compose.plugin.bash
Normal file
@@ -0,0 +1,20 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Helper functions for using docker-compose'
|
||||
|
||||
function docker-compose-fresh() {
|
||||
about 'Shut down, remove and start again the docker-compose setup, then tail the logs'
|
||||
group 'docker-compose'
|
||||
param '1: name of the docker-compose.yaml file to use (optional). Default: docker-compose.yaml'
|
||||
example 'docker-compose-fresh docker-compose-foo.yaml'
|
||||
|
||||
local DCO_FILE_PARAM=""
|
||||
if [ -n "$1" ]; then
|
||||
echo "Using docker-compose file: $1"
|
||||
DCO_FILE_PARAM="--file $1"
|
||||
fi
|
||||
|
||||
docker-compose $DCO_FILE_PARAM stop
|
||||
docker-compose $DCO_FILE_PARAM rm -f
|
||||
docker-compose $DCO_FILE_PARAM up -d
|
||||
docker-compose $DCO_FILE_PARAM logs -f --tail 100
|
||||
}
|
||||
5
dot_bash_it/plugins/available/docker-machine.plugin.bash
Normal file
5
dot_bash_it/plugins/available/docker-machine.plugin.bash
Normal file
@@ -0,0 +1,5 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Helpers to get Docker setup correctly for docker-machine'
|
||||
_log_warning '"docker-machine" is now deprecated, and as such the plugin for it is also deprecated.
|
||||
Please disable this plugin.'
|
||||
81
dot_bash_it/plugins/available/docker.plugin.bash
Normal file
81
dot_bash_it/plugins/available/docker.plugin.bash
Normal file
@@ -0,0 +1,81 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Helpers to more easily work with Docker'
|
||||
|
||||
function docker-remove-most-recent-container() {
|
||||
about 'attempt to remove the most recent container from docker ps -a'
|
||||
group 'docker'
|
||||
docker ps -ql | xargs docker rm
|
||||
}
|
||||
|
||||
function docker-remove-most-recent-image() {
|
||||
about 'attempt to remove the most recent image from docker images'
|
||||
group 'docker'
|
||||
docker images -q | head -1 | xargs docker rmi
|
||||
}
|
||||
|
||||
function docker-remove-stale-assets() {
|
||||
about 'attempt to remove exited containers and dangling images'
|
||||
group 'docker'
|
||||
docker ps --filter status=exited -q | xargs docker rm --volumes
|
||||
docker images --filter dangling=true -q | xargs docker rmi
|
||||
}
|
||||
|
||||
function docker-enter() {
|
||||
about 'enter the specified docker container using bash'
|
||||
group 'docker'
|
||||
param '1: Name of the container to enter'
|
||||
example 'docker-enter oracle-xe'
|
||||
|
||||
docker exec -it "$@" /bin/bash;
|
||||
}
|
||||
|
||||
function docker-remove-images() {
|
||||
about 'attempt to remove images with supplied tags or all if no tags are supplied'
|
||||
group 'docker'
|
||||
if [ -z "$1" ]; then
|
||||
docker rmi $(docker images -q)
|
||||
else
|
||||
DOCKER_IMAGES=""
|
||||
for IMAGE_ID in $@; do DOCKER_IMAGES="$DOCKER_IMAGES\|$IMAGE_ID"; done
|
||||
# Find the image IDs for the supplied tags
|
||||
ID_ARRAY=($(docker images | grep "${DOCKER_IMAGES:2}" | awk {'print $3'}))
|
||||
# Strip out duplicate IDs before attempting to remove the image(s)
|
||||
docker rmi $(echo ${ID_ARRAY[@]} | tr ' ' '\n' | sort -u | tr '\n' ' ')
|
||||
fi
|
||||
}
|
||||
|
||||
function docker-image-dependencies() {
|
||||
about 'attempt to create a Graphiz image of the supplied image ID dependencies'
|
||||
group 'docker'
|
||||
if hash dot 2>/dev/null; then
|
||||
OUT=$(mktemp -t docker-viz-XXXX.png)
|
||||
docker images -viz | dot -Tpng > $OUT
|
||||
case $OSTYPE in
|
||||
linux*)
|
||||
xdg-open $OUT
|
||||
;;
|
||||
darwin*)
|
||||
open $OUT
|
||||
;;
|
||||
esac
|
||||
else
|
||||
>&2 echo "Can't show dependencies; Graphiz is not installed"
|
||||
fi
|
||||
}
|
||||
|
||||
function docker-runtime-environment() {
|
||||
about 'attempt to list the environmental variables of the supplied image ID'
|
||||
group 'docker'
|
||||
docker run "$@" env
|
||||
}
|
||||
|
||||
function docker-archive-content() {
|
||||
about 'show the content of the provided Docker image archive'
|
||||
group 'docker'
|
||||
param '1: image archive name'
|
||||
example 'docker-archive-content images.tar.gz'
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
tar -xzOf $1 manifest.json | jq '[.[] | .RepoTags] | add'
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Enable emacs editing mode'
|
||||
|
||||
set -o emacs
|
||||
4
dot_bash_it/plugins/available/edit-mode-vi.plugin.bash
Normal file
4
dot_bash_it/plugins/available/edit-mode-vi.plugin.bash
Normal file
@@ -0,0 +1,4 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Enable vi editing mode'
|
||||
|
||||
set -o vi
|
||||
23
dot_bash_it/plugins/available/explain.plugin.bash
Normal file
23
dot_bash_it/plugins/available/explain.plugin.bash
Normal file
@@ -0,0 +1,23 @@
|
||||
cite about-plugin
|
||||
about-plugin 'mankier.com explain function to explain other commands'
|
||||
|
||||
explain () {
|
||||
about 'explain any bash command via mankier.com manpage API'
|
||||
param '1: Name of the command to explain'
|
||||
example '$ explain # interactive mode. Type commands to explain in REPL'
|
||||
example '$ explain '"'"'cmd -o | ...'"'"' # one quoted command to explain it.'
|
||||
group 'explain'
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
while read -p "Command: " cmd; do
|
||||
curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd"
|
||||
done
|
||||
echo "Bye!"
|
||||
elif [ "$#" -eq 1 ]; then
|
||||
curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1"
|
||||
else
|
||||
echo "Usage"
|
||||
echo "explain interactive mode."
|
||||
echo "explain 'cmd -o | ...' one quoted command to explain it."
|
||||
fi
|
||||
}
|
||||
73
dot_bash_it/plugins/available/extract.plugin.bash
Normal file
73
dot_bash_it/plugins/available/extract.plugin.bash
Normal file
@@ -0,0 +1,73 @@
|
||||
cite about-plugin
|
||||
about-plugin 'one command to extract them all...'
|
||||
|
||||
# extract file(s) from compressed status
|
||||
extract() {
|
||||
local opt
|
||||
local OPTIND=1
|
||||
while getopts "hv" opt; do
|
||||
case "$opt" in
|
||||
h)
|
||||
cat <<End-Of-Usage
|
||||
Usage: ${FUNCNAME[0]} [option] <archives>
|
||||
options:
|
||||
-h show this message and exit
|
||||
-v verbosely list files processed
|
||||
End-Of-Usage
|
||||
return
|
||||
;;
|
||||
v)
|
||||
local -r verbose='v'
|
||||
;;
|
||||
?)
|
||||
extract -h >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
[ $# -eq 0 ] && extract -h && return 1
|
||||
while [ $# -gt 0 ]; do
|
||||
if [[ ! -f "$1" ]]; then
|
||||
echo "extract: '$1' is not a valid file" >&2
|
||||
shift
|
||||
continue
|
||||
fi
|
||||
|
||||
local -r filename=$(basename -- $1)
|
||||
local -r filedirname=$(dirname -- $1)
|
||||
local targetdirname=$(sed 's/\(\.tar\.bz2$\|\.tbz$\|\.tbz2$\|\.tar\.gz$\|\.tgz$\|\.tar$\|\.tar\.xz$\|\.txz$\|\.tar\.Z$\|\.7z$\|\.nupkg$\|\.zip$\|\.war$\|\.jar$\)//g' <<< $filename)
|
||||
if [ "$filename" = "$targetdirname" ]; then
|
||||
# archive type either not supported or it doesn't need dir creation
|
||||
targetdirname=""
|
||||
else
|
||||
mkdir -v "$filedirname/$targetdirname"
|
||||
fi
|
||||
|
||||
if [ -f "$1" ]; then
|
||||
case "$1" in
|
||||
*.tar.bz2|*.tbz|*.tbz2) tar "x${verbose}jf" "$1" -C "$filedirname/$targetdirname" ;;
|
||||
*.tar.gz|*.tgz) tar "x${verbose}zf" "$1" -C "$filedirname/$targetdirname" ;;
|
||||
*.tar.xz|*.txz) tar "x${verbose}Jf" "$1" -C "$filedirname/$targetdirname" ;;
|
||||
*.tar.Z) tar "x${verbose}Zf" "$1" -C "$filedirname/$targetdirname" ;;
|
||||
*.bz2) bunzip2 "$1" ;;
|
||||
*.deb) dpkg-deb -x${verbose} "$1" "${1:0:-4}" ;;
|
||||
*.pax.gz) gunzip "$1"; set -- "$@" "${1:0:-3}" ;;
|
||||
*.gz) gunzip "$1" ;;
|
||||
*.pax) pax -r -f "$1" ;;
|
||||
*.pkg) pkgutil --expand "$1" "${1:0:-4}" ;;
|
||||
*.rar) unrar x "$1" ;;
|
||||
*.rpm) rpm2cpio "$1" | cpio -idm${verbose} ;;
|
||||
*.tar) tar "x${verbose}f" "$1" -C "$filedirname/$targetdirname" ;;
|
||||
*.xz) xz --decompress "$1" ;;
|
||||
*.zip|*.war|*.jar|*.nupkg) unzip "$1" -d "$filedirname/$targetdirname" ;;
|
||||
*.Z) uncompress "$1" ;;
|
||||
*.7z) 7za x -o"$filedirname/$targetdirname" "$1" ;;
|
||||
*) echo "'$1' cannot be extracted via extract" >&2;;
|
||||
esac
|
||||
fi
|
||||
|
||||
shift
|
||||
done
|
||||
}
|
||||
6
dot_bash_it/plugins/available/fasd.plugin.bash
Normal file
6
dot_bash_it/plugins/available/fasd.plugin.bash
Normal file
@@ -0,0 +1,6 @@
|
||||
cite about-plugin
|
||||
about-plugin 'load fasd, if you are using it'
|
||||
|
||||
_command_exists fasd || return
|
||||
|
||||
eval "$(fasd --init auto)"
|
||||
42
dot_bash_it/plugins/available/fzf.plugin.bash
Normal file
42
dot_bash_it/plugins/available/fzf.plugin.bash
Normal file
@@ -0,0 +1,42 @@
|
||||
# Load after the system completion to make sure that the fzf completions are working
|
||||
# BASH_IT_LOAD_PRIORITY: 375
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'load fzf, if you are using it'
|
||||
|
||||
if [ -r ~/.fzf.bash ] ; then
|
||||
source ~/.fzf.bash
|
||||
elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ] ; then
|
||||
source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash
|
||||
fi
|
||||
|
||||
# No need to continue if the command is not present
|
||||
_command_exists fzf || return
|
||||
|
||||
if [ -z ${FZF_DEFAULT_COMMAND+x} ] && _command_exists fd ; then
|
||||
export FZF_DEFAULT_COMMAND='fd --type f'
|
||||
fi
|
||||
|
||||
fe() {
|
||||
about "Open the selected file in the default editor"
|
||||
group "fzf"
|
||||
param "1: Search term"
|
||||
example "fe foo"
|
||||
|
||||
local IFS=$'\n'
|
||||
local files
|
||||
files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
|
||||
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
|
||||
}
|
||||
|
||||
fcd() {
|
||||
about "cd to the selected directory"
|
||||
group "fzf"
|
||||
param "1: Directory to browse, or . if omitted"
|
||||
example "fcd aliases"
|
||||
|
||||
local dir
|
||||
dir=$(find ${1:-.} -path '*/\.*' -prune \
|
||||
-o -type d -print 2> /dev/null | fzf +m) &&
|
||||
cd "$dir"
|
||||
}
|
||||
321
dot_bash_it/plugins/available/gif.plugin.bash
Normal file
321
dot_bash_it/plugins/available/gif.plugin.bash
Normal file
@@ -0,0 +1,321 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'video to gif, gif to WebM helper functions'
|
||||
|
||||
# Based loosely on:
|
||||
# https://gist.github.com/SlexAxton/4989674#comment-1199058
|
||||
# https://linustechtips.com/main/topic/343253-tutorial-convert-videogifs-to-webm/
|
||||
# and other sources
|
||||
# Renamed gifify to v2gif to go avoid clobbering https://github.com/jclem/gifify
|
||||
# Requirements (Mac OS X using Homebrew): brew install ffmpeg giflossy imagemagick
|
||||
# Requirements on Ubuntu: sudo apt install ffmpeg imagemagick ; plus install https://github.com/pornel/giflossy
|
||||
# Optional: install mediainfo for autodetection of original video FPS.
|
||||
# Optional: if lossy is not important, Ubuntu has gifsicle packaged for apt-get, instead of giflossy
|
||||
# Optional: gifski (from `brew install gifski` or github.com/ImageOptim/gifski)
|
||||
# for high quality huge files.
|
||||
function v2gif() {
|
||||
about 'Converts a .mov/.avi/.mp4 file into an into an animated GIF.'
|
||||
group 'gif'
|
||||
param '1: MOV/AVI/MP4 file name(s)'
|
||||
param '2: -w <num> ; Optional: max width in pixels'
|
||||
param '3: -l <num> ; Optional: extra lossy level for smaller files (80-200 make sense, needs giflossy instead of gifsicle)'
|
||||
param '4: -h ; Optional: high quality using gifski (installed seperately) - overrides "--lossy" above!'
|
||||
param '5: -d ; Optional: delete the original video file if succeeded'
|
||||
param '6: -t ; Optional: Tag the result with quality stamp for comparison use'
|
||||
param '7: -f <num> ; Optional: Change number of frames per second (default 10 or original FPS if mediainfo installed)'
|
||||
param '8: -a <num> ; Optional: Alert if resulting file is over <num> kilobytes (default is 5000, 0 turns off)'
|
||||
param '9: -m ; Optional: Also create a WebM file (will one day replace GIF, Smaller and higher quality than mp4)'
|
||||
example '$ v2gif foo.mov'
|
||||
example '$ v2gif foo.mov -w 600'
|
||||
example '$ v2gif -l 100 -d *.mp4'
|
||||
example '$ v2gif -dh *.avi'
|
||||
example '$ v2gif -thw 600 *.avi *.mov'
|
||||
|
||||
local convert ffmpeg mediainfo gifsicle getopt args gifski out_size
|
||||
|
||||
convert="$(type -p convert)"
|
||||
[[ -x "$convert" ]] || {
|
||||
echo "No convert found!"
|
||||
return 2
|
||||
}
|
||||
ffmpeg="$(type -p ffmpeg)"
|
||||
[[ -x "$ffmpeg" ]] || {
|
||||
echo "No ffmpeg found!"
|
||||
return 2
|
||||
}
|
||||
mediainfo="$(type -p mediainfo)"
|
||||
[[ -x "$mediainfo" ]] || {
|
||||
echo "No mediainfo found!"
|
||||
return 2
|
||||
}
|
||||
gifsicle="$(type -p gifsicle)"
|
||||
[[ -x "$gifsicle" ]] || {
|
||||
echo "No gifsicle found!"
|
||||
return 2
|
||||
}
|
||||
getopt="$(type -p getopt)"
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# Getopt on BSD is incompatible with GNU
|
||||
getopt=/usr/local/opt/gnu-getopt/bin/getopt
|
||||
[[ -x "$getopt" ]] || {
|
||||
echo "No GNU-getopt found!"
|
||||
return 2
|
||||
}
|
||||
fi
|
||||
|
||||
# Parse the options
|
||||
args=$("$getopt" -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@") || {
|
||||
echo 'Terminating...' >&2
|
||||
return 2
|
||||
}
|
||||
|
||||
eval set -- "$args"
|
||||
local use_gifski=""
|
||||
local opt_del_after=""
|
||||
local maxsize=""
|
||||
local lossiness=""
|
||||
local maxwidthski=""
|
||||
local giftagopt=""
|
||||
local giftag=""
|
||||
local defaultfps=10
|
||||
local infps=""
|
||||
local fps=""
|
||||
local make_webm=""
|
||||
local alert=5000
|
||||
while [[ $# -ge 1 ]]; do
|
||||
case "$1" in
|
||||
--)
|
||||
# No more options left.
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-d | --del | --delete)
|
||||
# Delete after
|
||||
opt_del_after="true"
|
||||
shift
|
||||
;;
|
||||
-h | --high)
|
||||
#High Quality, use gifski
|
||||
gifski="$(type -p gifski)"
|
||||
[[ -x "$gifski" ]] || {
|
||||
echo "No gifski found!"
|
||||
return 2
|
||||
}
|
||||
use_gifski=true
|
||||
giftag="${giftag}-h"
|
||||
shift
|
||||
;;
|
||||
-w | --width)
|
||||
maxsize="-vf scale=$2:-1"
|
||||
maxwidthski="-W $2"
|
||||
giftag="${giftag}-w$2"
|
||||
shift 2
|
||||
;;
|
||||
-t | --tag)
|
||||
# mark with a quality tag
|
||||
giftagopt="true"
|
||||
shift
|
||||
;;
|
||||
-l | --lossy)
|
||||
# Use giflossy parameter
|
||||
lossiness="--lossy=$2"
|
||||
giftag="${giftag}-l$2"
|
||||
shift 2
|
||||
;;
|
||||
-f | --fps)
|
||||
# select fps
|
||||
infps="$2"
|
||||
giftag="${giftag}-f$2"
|
||||
shift 2
|
||||
;;
|
||||
-a | --alert)
|
||||
# set size alert
|
||||
alert="$2"
|
||||
shift 2
|
||||
;;
|
||||
-m | --webm)
|
||||
# set size alert
|
||||
make_webm="true"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$*" ]]; then
|
||||
echo "$(tput setaf 1)No input files given. Example: v2gif file [file...] [-w <max width (pixels)>] [-l <lossy level>] $(tput sgr 0)"
|
||||
echo "-d/--del/--delete Delete original vid if done suceessfully (and file not over the size limit)"
|
||||
echo "-h/--high High Quality - use Gifski instead of gifsicle"
|
||||
echo "-w/--width N Lock maximum gif width to N pixels, resize if necessary"
|
||||
echo "-t/--tag Add a tag to the output gif describing the options used (useful for comparing several options)"
|
||||
echo "-l/--lossy N Use the Giflossy parameter for gifsicle (If your version supports it)"
|
||||
echo "-f/--fps N Override autodetection of incoming vid FPS (useful for downsampling)"
|
||||
echo "-a/--alert N Alert if over N kilobytes (Defaults to 5000)"
|
||||
echo "-m/--webm Also create a webm file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Prepare the quality tag if requested.
|
||||
[[ -z "$giftag" ]] && giftag="-default"
|
||||
[[ -z "$giftagopt" ]] && giftag=""
|
||||
|
||||
for file; do
|
||||
|
||||
local output_file="${file%.*}${giftag}.gif"
|
||||
local del_after=$opt_del_after
|
||||
|
||||
if [[ -n "$make_webm" ]]; then
|
||||
$ffmpeg -loglevel panic -i "$file" \
|
||||
-c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 \
|
||||
-quality best -loop 0 "${file%.*}.webm" || return 2
|
||||
fi
|
||||
|
||||
# Set FPS to match the video if possible, otherwise fallback to default.
|
||||
if [[ -n "$infps" ]]; then
|
||||
fps=$infps
|
||||
else
|
||||
fps=$defaultfps
|
||||
if [[ -x "$mediainfo" ]]; then
|
||||
fps=$($mediainfo "$file" | grep "Frame rate " | sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
|
||||
[[ -z "$fps" ]] && fps=$($mediainfo "$file" | grep "Minimum frame rate" | sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$(tput setaf 2)Creating '$output_file' at $fps FPS ...$(tput sgr 0)"
|
||||
|
||||
if [[ "$use_gifski" = "true" ]]; then
|
||||
# I trust @pornel to do his own resizing optimization choices
|
||||
$ffmpeg -loglevel panic -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \
|
||||
&& $gifski v2gif-tmp-*.png "$maxwidthski" --fps "$(printf "%.0f" "$fps")" -o "$output_file" || return 2
|
||||
else
|
||||
$ffmpeg -loglevel panic -i "$file" "$maxsize" -r "$fps" -vcodec png v2gif-tmp-%05d.png \
|
||||
&& $convert +dither -layers Optimize v2gif-tmp-*.png GIF:- \
|
||||
| $gifsicle "$lossiness" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2
|
||||
fi
|
||||
|
||||
rm v2gif-tmp-*.png
|
||||
|
||||
# Checking if the file is bigger than Twitter likes and warn
|
||||
if [[ $alert -gt 0 ]]; then
|
||||
out_size=$(wc --bytes < "$output_file")
|
||||
if [[ $out_size -gt $((alert * 1000)) ]]; then
|
||||
echo "$(tput setaf 3)Warning: '$output_file' is $((out_size / 1000))kb.$(tput sgr 0)"
|
||||
[[ "$del_after" == "true" ]] && echo "$(tput setaf 3)Warning: Keeping '$file' even though --del requested.$(tput sgr 0)"
|
||||
del_after=""
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ "$del_after" = "true" ]] && rm "$file"
|
||||
|
||||
done
|
||||
|
||||
echo "$(tput setaf 2)Done.$(tput sgr 0)"
|
||||
}
|
||||
|
||||
function any2webm() {
|
||||
about 'Converts an movies and Animated GIF files into an into a modern quality WebM video.'
|
||||
group 'gif'
|
||||
param '1: GIF/video file name(s)'
|
||||
param '2: -s <WxH> ; Optional: set <W>idth and <H>eight in pixels'
|
||||
param '3: -d ; Optional: delete the original file if succeeded'
|
||||
param '4: -t ; Optional: Tag the result with quality stamp for comparison use'
|
||||
param '5: -f <num> ; Optional: Change number of frames per second'
|
||||
param '6: -b <num> ; Optional: Set Bandwidth (quality/size of resulting file), Defaults to 2M (bits/sec, accepts fractions)"'
|
||||
param '7: -a <num> ; Optional: Alert if resulting file is over <num> kilobytes (default is 5000, 0 turns off)'
|
||||
example '$ any2webm foo.gif'
|
||||
example '$ any2webm *.mov -b 1.5M -s 600x480'
|
||||
|
||||
local args out_size
|
||||
|
||||
# Parse the options
|
||||
args=$(getopt -l alert -l "bandwidth:" -l "width:" -l del,delete -l tag -l "fps:" -l webm -o "a:b:w:f:dt" -- "$@") || {
|
||||
echo 'Terminating...' >&2
|
||||
return 2
|
||||
}
|
||||
|
||||
eval set -- "$args"
|
||||
local opt_del_after=""
|
||||
local size=""
|
||||
local webmtagopt=""
|
||||
local webmtag=""
|
||||
local defaultfps=10
|
||||
local fps=""
|
||||
local bandwidth="2M"
|
||||
local alert=5000
|
||||
while [[ $# -ge 1 ]]; do
|
||||
case "$1" in
|
||||
--)
|
||||
# No more options left.
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-d | --del | --delete)
|
||||
# Delete after
|
||||
opt_del_after="true"
|
||||
shift
|
||||
;;
|
||||
-s | --size)
|
||||
size="-s $2"
|
||||
webmtag="${webmtag}-s$2"
|
||||
shift 2
|
||||
;;
|
||||
-t | --tag)
|
||||
# mark with a quality tag
|
||||
webmtagopt="true"
|
||||
shift
|
||||
;;
|
||||
-f | --fps)
|
||||
# select fps
|
||||
fps="-r $2"
|
||||
webmtag="${webmtag}-f$2"
|
||||
shift 2
|
||||
;;
|
||||
-b | --bandwidth)
|
||||
# select bandwidth
|
||||
bandwidth="$2"
|
||||
webmtag="${webmtag}-b$2"
|
||||
shift 2
|
||||
;;
|
||||
-a | --alert)
|
||||
# set size alert
|
||||
alert="$2"
|
||||
shift 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$*" ]]; then
|
||||
echo "$(tput setaf 1)No input files given. Example: any2webm file [file...] [-w <max width (pixels)>] < $(tput sgr 0)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Prepare the quality tag if requested.
|
||||
[[ -z "$webmtag" ]] && webmtag="-default"
|
||||
[[ -z "$webmtagopt" ]] && webmtag=""
|
||||
|
||||
for file; do
|
||||
|
||||
local output_file="${file%.*}${webmtag}.webm"
|
||||
local del_after=$opt_del_after
|
||||
|
||||
echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)"
|
||||
|
||||
$ffmpeg -loglevel panic -i "$file" \
|
||||
-c:v libvpx -crf 4 -threads 0 -an -b:v "$bandwidth" -auto-alt-ref 0 \
|
||||
-quality best "$fps" "$size" -loop 0 -pix_fmt yuva420p "$output_file" || return 2
|
||||
|
||||
# Checking if the file is bigger than Twitter likes and warn
|
||||
if [[ $alert -gt 0 ]]; then
|
||||
out_size=$(wc --bytes < "$output_file")
|
||||
if [[ $out_size -gt $((alert * 1000)) ]]; then
|
||||
echo "$(tput setaf 3)Warning: '$output_file' is $((out_size / 1000))kb.$(tput sgr 0)"
|
||||
[[ "$del_after" == "true" ]] && echo "$(tput setaf 3)Warning: Keeping '$file' even though --del requested.$(tput sgr 0)"
|
||||
del_after=""
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ "$del_after" = "true" ]] && rm "$file"
|
||||
|
||||
done
|
||||
|
||||
echo "$(tput setaf 2)Done.$(tput sgr 0)"
|
||||
}
|
||||
7
dot_bash_it/plugins/available/git-subrepo.plugin.bash
Normal file
7
dot_bash_it/plugins/available/git-subrepo.plugin.bash
Normal file
@@ -0,0 +1,7 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'load git-subrepo if you are using it, and initialize completions'
|
||||
|
||||
if [[ -s "${GIT_SUBREPO_ROOT:=$HOME/.git-subrepo}/init" ]]; then
|
||||
# shellcheck disable=SC1091
|
||||
source "$GIT_SUBREPO_ROOT/init"
|
||||
fi
|
||||
316
dot_bash_it/plugins/available/git.plugin.bash
Normal file
316
dot_bash_it/plugins/available/git.plugin.bash
Normal file
@@ -0,0 +1,316 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'git helper functions'
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
function git_remote {
|
||||
about 'adds remote $GIT_HOSTING:$1 to current repo'
|
||||
group "git"
|
||||
|
||||
echo "Running: git remote add origin ${GIT_HOSTING:?}:$1.git"
|
||||
git remote add origin "${GIT_HOSTING}:${1}".git
|
||||
}
|
||||
|
||||
function git_first_push {
|
||||
about 'push into origin refs/heads/master'
|
||||
group 'git'
|
||||
|
||||
echo "Running: git push origin master:refs/heads/master"
|
||||
git push origin master:refs/heads/master
|
||||
}
|
||||
|
||||
function git_pub() {
|
||||
about 'publishes current branch to remote origin'
|
||||
group 'git'
|
||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
echo "Publishing ${BRANCH} to remote origin"
|
||||
git push -u origin "${BRANCH}"
|
||||
}
|
||||
|
||||
function git_revert() {
|
||||
about 'applies changes to HEAD that revert all changes after this commit'
|
||||
group 'git'
|
||||
|
||||
git reset "${1:?}"
|
||||
git reset --soft "HEAD@{1}"
|
||||
git commit -m "Revert to ${1}"
|
||||
git reset --hard
|
||||
}
|
||||
|
||||
function git_rollback() {
|
||||
about 'resets the current HEAD to this commit'
|
||||
group 'git'
|
||||
|
||||
function is_clean() {
|
||||
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
|
||||
echo "Your branch is dirty, please commit your changes"
|
||||
kill -INT $$
|
||||
fi
|
||||
}
|
||||
|
||||
function commit_exists() {
|
||||
if git rev-list --quiet "${1:?}"; then
|
||||
echo "Commit ${1} does not exist"
|
||||
kill -INT $$
|
||||
fi
|
||||
}
|
||||
|
||||
function keep_changes() {
|
||||
while true; do
|
||||
# shellcheck disable=SC2162
|
||||
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
|
||||
case "${RESP}" in
|
||||
|
||||
[yY])
|
||||
echo "Rolling back to commit ${1} with unstaged changes"
|
||||
git reset "$1"
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
echo "Rolling back to commit ${1} with a clean working tree"
|
||||
git reset --hard "$1"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
is_clean
|
||||
commit_exists "$1"
|
||||
|
||||
while true; do
|
||||
# shellcheck disable=SC2162
|
||||
read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP
|
||||
case "${RESP}" in
|
||||
|
||||
[yY])
|
||||
keep_changes "$1"
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
}
|
||||
|
||||
function git_remove_missing_files() {
|
||||
about "git rm's missing files"
|
||||
group 'git'
|
||||
|
||||
git ls-files -d -z | xargs -0 git update-index --remove
|
||||
}
|
||||
|
||||
# Adds files to git's exclude file (same as .gitignore)
|
||||
function local-ignore() {
|
||||
about 'adds file or path to git exclude file'
|
||||
param '1: file or path fragment to ignore'
|
||||
group 'git'
|
||||
echo "$1" >> .git/info/exclude
|
||||
}
|
||||
|
||||
# get a quick overview for your git repo
|
||||
function git_info() {
|
||||
about 'overview for your git repo'
|
||||
group 'git'
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
# print informations
|
||||
echo "git repo overview"
|
||||
echo "-----------------"
|
||||
echo
|
||||
|
||||
# print all remotes and thier details
|
||||
for remote in $(git remote show); do
|
||||
echo "${remote}":
|
||||
git remote show "${remote}"
|
||||
echo
|
||||
done
|
||||
|
||||
# print status of working repo
|
||||
echo "status:"
|
||||
if [ -n "$(git status -s 2> /dev/null)" ]; then
|
||||
git status -s
|
||||
else
|
||||
echo "working directory is clean"
|
||||
fi
|
||||
|
||||
# print at least 5 last log entries
|
||||
echo
|
||||
echo "log:"
|
||||
git log -5 --oneline
|
||||
echo
|
||||
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
function git_stats {
|
||||
about 'display stats per author'
|
||||
group 'git'
|
||||
|
||||
# awesome work from https://github.com/esc/git-stats
|
||||
# including some modifications
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
echo "Number of commits per author:"
|
||||
git --no-pager shortlog -sn --all
|
||||
AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
|
||||
LOGOPTS=""
|
||||
if [ "$1" == '-w' ]; then
|
||||
LOGOPTS="${LOGOPTS} -w"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-M' ]; then
|
||||
LOGOPTS="${LOGOPTS} -M"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-C' ]; then
|
||||
LOGOPTS="${LOGOPTS} -C --find-copies-harder"
|
||||
shift
|
||||
fi
|
||||
for a in ${AUTHORS}; do
|
||||
echo '-------------------'
|
||||
echo "Statistics for: ${a}"
|
||||
echo -n "Number of files changed: "
|
||||
# shellcheck disable=SC2086
|
||||
git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f3 | sort -iu | wc -l
|
||||
echo -n "Number of lines added: "
|
||||
# shellcheck disable=SC2086
|
||||
git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f1 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of lines deleted: "
|
||||
# shellcheck disable=SC2086
|
||||
git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f2 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of merges: "
|
||||
# shellcheck disable=SC2086
|
||||
git log ${LOGOPTS} --all --merges --author="${a}" | grep -c '^commit'
|
||||
done
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
}
|
||||
|
||||
function gittowork() {
|
||||
about 'Places the latest .gitignore file for a given project type in the current directory, or concatenates onto an existing .gitignore'
|
||||
group 'git'
|
||||
param '1: the language/type of the project, used for determining the contents of the .gitignore file'
|
||||
example '$ gittowork java'
|
||||
|
||||
result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null)
|
||||
|
||||
if [[ "${result}" =~ ERROR ]]; then
|
||||
echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'"
|
||||
elif [[ $1 == list ]]; then
|
||||
echo "${result}"
|
||||
else
|
||||
if [[ -f .gitignore ]]; then
|
||||
result=$(grep -v "# Created by http://www.gitignore.io" <<< "${result}")
|
||||
echo ".gitignore already exists, appending..."
|
||||
fi
|
||||
echo "${result}" >> .gitignore
|
||||
fi
|
||||
}
|
||||
|
||||
function gitignore-reload() {
|
||||
about 'Empties the git cache, and readds all files not blacklisted by .gitignore'
|
||||
group 'git'
|
||||
example '$ gitignore-reload'
|
||||
|
||||
# The .gitignore file should not be reloaded if there are uncommited changes.
|
||||
# Firstly, require a clean work tree. The function require_clean_work_tree()
|
||||
# was stolen with love from https://www.spinics.net/lists/git/msg142043.html
|
||||
|
||||
# Begin require_clean_work_tree()
|
||||
|
||||
# Update the index
|
||||
git update-index -q --ignore-submodules --refresh
|
||||
err=0
|
||||
|
||||
# Disallow unstaged changes in the working tree
|
||||
if ! git diff-files --quiet --ignore-submodules --; then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains unstaged changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
|
||||
# Disallow uncommited changes in the index
|
||||
if ! git diff-index --cached --quiet HEAD --ignore-submodules; then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains uncommited changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
|
||||
# Prompt user to commit or stash changes and exit
|
||||
if [[ "${err}" == 1 ]]; then
|
||||
echo >&2 "Please commit or stash them."
|
||||
fi
|
||||
|
||||
# End require_clean_work_tree()
|
||||
|
||||
# If we're here, then there are no uncommited or unstaged changes dangling around.
|
||||
# Proceed to reload .gitignore
|
||||
if [[ "${err}" == 0 ]]; then
|
||||
# Remove all cached files
|
||||
git rm -r --cached .
|
||||
|
||||
# Re-add everything. The changed .gitignore will be picked up here and will exclude the files
|
||||
# now blacklisted by .gitignore
|
||||
echo >&2 "Running git add ."
|
||||
git add .
|
||||
echo >&2 "Files readded. Commit your new changes now."
|
||||
fi
|
||||
}
|
||||
|
||||
function git-changelog() {
|
||||
# ---------------------------------------------------------------
|
||||
# ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 |
|
||||
# ---------------------------------------------------------------
|
||||
about 'Creates the git changelog from one point to another by date'
|
||||
group 'git'
|
||||
example '$ git-changelog origin/master...origin/release [md|txt]'
|
||||
|
||||
if [[ "$1" != *"..."* ]]; then
|
||||
echo "Please include the valid 'diff' to make changelog"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local NEXT=$(date +%F)
|
||||
|
||||
if [[ "$2" == "md" ]]; then
|
||||
echo "# CHANGELOG $1"
|
||||
|
||||
# shellcheck disable=SC2162
|
||||
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
|
||||
echo
|
||||
echo "### ${DATE}"
|
||||
git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00"
|
||||
NEXT=${DATE}
|
||||
done
|
||||
else
|
||||
echo "CHANGELOG $1"
|
||||
echo ----------------------
|
||||
|
||||
# shellcheck disable=SC2162
|
||||
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
|
||||
echo
|
||||
echo "[${DATE}]"
|
||||
git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00"
|
||||
# shellcheck disable=SC2034
|
||||
NEXT=${DATE}
|
||||
done
|
||||
fi
|
||||
}
|
||||
26
dot_bash_it/plugins/available/gitstatus.plugin.bash
Normal file
26
dot_bash_it/plugins/available/gitstatus.plugin.bash
Normal file
@@ -0,0 +1,26 @@
|
||||
cite about-plugin
|
||||
about-plugin 'speeds up your life by using gitstatus for git status calculations. install from https://github.com/romkatv/gitstatus'
|
||||
|
||||
function gitstatus_on_disable() {
|
||||
about 'Destructor of gitstatus plugin'
|
||||
group 'gitstatus'
|
||||
|
||||
unset SCM_GIT_USE_GITSTATUS
|
||||
_command_exists gitstatus_stop && gitstatus_stop
|
||||
}
|
||||
|
||||
# No scm-check
|
||||
[[ $SCM_CHECK == "true" ]] || return
|
||||
|
||||
# non-interactive shell
|
||||
[[ $- == *i* ]] || return
|
||||
|
||||
: "${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"}"
|
||||
if [[ -d ${SCM_GIT_GITSTATUS_DIR} ]]; then
|
||||
source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh"
|
||||
# Start the actual gitstatus binary
|
||||
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1
|
||||
export SCM_GIT_USE_GITSTATUS=true
|
||||
else
|
||||
_log_warning "Could not find gitstatus directory in ${SCM_GIT_GITSTATUS_DIR}. Please specify directory location using SCM_GIT_GITSTATUS_DIR."
|
||||
fi
|
||||
36
dot_bash_it/plugins/available/go.plugin.bash
Normal file
36
dot_bash_it/plugins/available/go.plugin.bash
Normal file
@@ -0,0 +1,36 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'go environment variables & path configuration'
|
||||
|
||||
# Load after basher and goenv
|
||||
# BASH_IT_LOAD_PRIORITY: 270
|
||||
|
||||
# Test `go version` because goenv creates shim scripts that will be found in PATH
|
||||
# but do not always resolve to a working install.
|
||||
{ _command_exists go && go version &> /dev/null; } || return 0
|
||||
|
||||
export GOROOT="${GOROOT:-$(go env GOROOT)}"
|
||||
export GOPATH="${GOPATH:-$(go env GOPATH)}"
|
||||
|
||||
# $GOPATH/bin is the default location for binaries. Because GOPATH accepts a list of paths and each
|
||||
# might be managed differently, we add each path's /bin folder to PATH using pathmunge,
|
||||
# while preserving ordering.
|
||||
# e.g. GOPATH=foo:bar -> PATH=foo/bin:bar/bin
|
||||
_bash-it-gopath-pathmunge() {
|
||||
_about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended'
|
||||
_group 'go'
|
||||
if [[ -z $GOPATH ]]; then
|
||||
echo 'GOPATH empty' >&2
|
||||
return 1
|
||||
fi
|
||||
local paths i
|
||||
IFS=: read -r -a paths <<< "$GOPATH"
|
||||
i=${#paths[@]}
|
||||
while [[ $i -gt 0 ]]; do
|
||||
i=$((i - 1))
|
||||
if [[ -n "${paths[i]}" ]]; then
|
||||
pathmunge "${paths[i]}/bin"
|
||||
fi
|
||||
done
|
||||
}
|
||||
_bash-it-gopath-pathmunge
|
||||
42
dot_bash_it/plugins/available/goenv.plugin.bash
Normal file
42
dot_bash_it/plugins/available/goenv.plugin.bash
Normal file
@@ -0,0 +1,42 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load goenv, if you are using it'
|
||||
|
||||
# https://github.com/syndbg/goenv
|
||||
|
||||
# Load after basher
|
||||
# BASH_IT_LOAD_PRIORITY: 260
|
||||
|
||||
# Don't modify the environment if we can't find the tool:
|
||||
# - Check if in $PATH already
|
||||
# - Check if installed manually to $GOENV_ROOT
|
||||
# - Check if installed manually to $HOME
|
||||
_command_exists goenv \
|
||||
|| [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] \
|
||||
|| [[ -x "$HOME/.goenv/bin/goenv" ]] \
|
||||
|| return 0
|
||||
|
||||
# Set GOENV_ROOT, if not already set
|
||||
export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}"
|
||||
|
||||
# Add GOENV_ROOT/bin to PATH, if that's where it's installed
|
||||
if ! _command_exists goenv && [[ -x "$GOENV_ROOT/bin/goenv" ]]; then
|
||||
pathmunge "$GOENV_ROOT/bin"
|
||||
fi
|
||||
|
||||
# Initialize goenv
|
||||
eval "$(goenv init - bash)"
|
||||
|
||||
# If moving to a directory with a goenv version set, reload the shell
|
||||
# to ensure the shell environment matches expectations.
|
||||
_bash-it-goenv-preexec() {
|
||||
GOENV_OLD_VERSION="$(goenv version-name)"
|
||||
}
|
||||
_bash-it-goenv-precmd() {
|
||||
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then
|
||||
exec env -u PATH -u GOROOT -u GOPATH -u GOENV_OLD_VERSION "${0/-/}" --login
|
||||
fi
|
||||
unset GOENV_OLD_VERSION
|
||||
}
|
||||
preexec_functions+=(_bash-it-goenv-preexec)
|
||||
precmd_functions+=(_bash-it-goenv-precmd)
|
||||
12
dot_bash_it/plugins/available/gradle.plugin.bash
Normal file
12
dot_bash_it/plugins/available/gradle.plugin.bash
Normal file
@@ -0,0 +1,12 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Add a gw command to use gradle wrapper if present, else use system gradle'
|
||||
|
||||
function gw() {
|
||||
local file="gradlew"
|
||||
local result
|
||||
|
||||
result="$(_bash-it-find-in-ancestor "${file}")"
|
||||
|
||||
# Call gradle
|
||||
"${result:-gradle}" $*
|
||||
}
|
||||
25
dot_bash_it/plugins/available/hg.plugin.bash
Normal file
25
dot_bash_it/plugins/available/hg.plugin.bash
Normal file
@@ -0,0 +1,25 @@
|
||||
cite about-plugin
|
||||
about-plugin 'hg helper functions'
|
||||
|
||||
hg_dirty() {
|
||||
about 'displays dirty status of hg repository'
|
||||
group 'hg'
|
||||
|
||||
hg status --no-color 2> /dev/null \
|
||||
| awk '$1 == "?" { print "?" } $1 != "?" { print "!" }' \
|
||||
| sort | uniq | head -c1
|
||||
}
|
||||
|
||||
hg_in_repo() {
|
||||
about 'determine if pwd is an hg repo'
|
||||
group 'hg'
|
||||
|
||||
[[ `hg branch 2> /dev/null` ]] && echo 'on '
|
||||
}
|
||||
|
||||
hg_branch() {
|
||||
about 'display current hg branch'
|
||||
group 'hg'
|
||||
|
||||
hg branch 2> /dev/null
|
||||
}
|
||||
22
dot_bash_it/plugins/available/history-eternal.plugin.bash
Normal file
22
dot_bash_it/plugins/available/history-eternal.plugin.bash
Normal file
@@ -0,0 +1,22 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'eternal bash history'
|
||||
|
||||
if [[ ${BASH_VERSINFO[0]} -lt 4 ]] || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then
|
||||
_log_warning "Bash version 4.3 introduced the 'unlimited' history size capability."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Modify history sizes before changing location to avoid unintentionally
|
||||
# truncating the history file early.
|
||||
|
||||
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)"
|
||||
readonly HISTSIZE=-1 2> /dev/null || true
|
||||
|
||||
# "Non-numeric values and numeric values less than zero inhibit truncation"
|
||||
readonly HISTFILESIZE='unlimited' 2> /dev/null || true
|
||||
|
||||
# Use a custom history file location so history is not truncated
|
||||
# if the environment ever loses this "eternal" configuration.
|
||||
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
|
||||
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
|
||||
readonly HISTFILE="${HISTDIR?}/history" 2> /dev/null || true
|
||||
9
dot_bash_it/plugins/available/history-search.plugin.bash
Normal file
9
dot_bash_it/plugins/available/history-search.plugin.bash
Normal file
@@ -0,0 +1,9 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'search history using the prefix already entered'
|
||||
|
||||
# enter a few characters and press UpArrow/DownArrow
|
||||
# to search backwards/forwards through the history
|
||||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
||||
bind '"\e[A":history-search-backward'
|
||||
bind '"\e[B":history-search-forward'
|
||||
fi
|
||||
@@ -0,0 +1,9 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'search history using the substring already entered'
|
||||
|
||||
# enter a few characters and press UpArrow/DownArrow
|
||||
# to search backwards/forwards through the history
|
||||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
||||
bind '"\e[A":history-substring-search-backward'
|
||||
bind '"\e[B":history-substring-search-forward'
|
||||
fi
|
||||
36
dot_bash_it/plugins/available/history.plugin.bash
Normal file
36
dot_bash_it/plugins/available/history.plugin.bash
Normal file
@@ -0,0 +1,36 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'improve history handling with sane defaults'
|
||||
|
||||
# Append the history list to the file named by the value of the HISTFILE
|
||||
# variable when the shell exits, rather than overwriting the file.
|
||||
shopt -s histappend
|
||||
|
||||
# 'ignorespace': don't save command lines which begin with a space to history
|
||||
# 'erasedups' (alternative 'ignoredups'): don't save duplicates to history
|
||||
# 'autoshare': automatically share history between multiple running shells
|
||||
: "${HISTCONTROL:=ignorespace:erasedups:autoshare}"
|
||||
|
||||
# resize history to 100x the default (500)
|
||||
: "${HISTSIZE:=50000}"
|
||||
|
||||
function top-history() {
|
||||
about 'print the name and count of the most commonly run tools'
|
||||
|
||||
# - Make sure formatting doesn't interfer with our parsing
|
||||
# - Use awk to count how many times the first command on each line has been called
|
||||
# - Truncate to 10 lines
|
||||
# - Print in column format
|
||||
HISTTIMEFORMAT='' history \
|
||||
| awk '{
|
||||
a[$2]++
|
||||
}END{
|
||||
for(i in a)
|
||||
printf("%s\t%s\n", a[i], i)
|
||||
}' \
|
||||
| sort --reverse --numeric-sort \
|
||||
| head \
|
||||
| column \
|
||||
--table \
|
||||
--table-columns 'Command Count,Command Name' \
|
||||
--output-separator ' | '
|
||||
}
|
||||
7
dot_bash_it/plugins/available/hub.plugin.bash
Normal file
7
dot_bash_it/plugins/available/hub.plugin.bash
Normal file
@@ -0,0 +1,7 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load hub, if you are using it'
|
||||
|
||||
if _command_exists hub; then
|
||||
eval "$(hub alias -s)"
|
||||
fi
|
||||
11
dot_bash_it/plugins/available/java.plugin.bash
Normal file
11
dot_bash_it/plugins/available/java.plugin.bash
Normal file
@@ -0,0 +1,11 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'Java and JAR helper functions'
|
||||
|
||||
function jar_manifest {
|
||||
about "extracts the specified JAR file's MANIFEST file and prints it to stdout"
|
||||
group 'java'
|
||||
param '1: JAR file to extract the MANIFEST from'
|
||||
example 'jar_manifest lib/foo.jar'
|
||||
|
||||
unzip -c "${1:?${FUNCNAME[0]}: JAR file must be specified}" META-INF/MANIFEST.MF
|
||||
}
|
||||
41
dot_bash_it/plugins/available/javascript.plugin.bash
Normal file
41
dot_bash_it/plugins/available/javascript.plugin.bash
Normal file
@@ -0,0 +1,41 @@
|
||||
# The install directory is hard-coded. TODO: allow the directory to be specified on the command line.
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'download jquery files into current project'
|
||||
|
||||
[[ -z "$JQUERY_VERSION_NUMBER" ]] && JQUERY_VERSION_NUMBER="1.6.1"
|
||||
[[ -z "$JQUERY_UI_VERSION_NUMBER" ]] && JQUERY_UI_VERSION_NUMBER="1.8.13"
|
||||
|
||||
function rails_jquery {
|
||||
about 'download rails.js into public/javascripts'
|
||||
group 'javascript'
|
||||
|
||||
curl -o public/javascripts/rails.js http://github.com/rails/jquery-ujs/raw/master/src/rails.js
|
||||
}
|
||||
|
||||
function jquery_install {
|
||||
about 'download jquery.js into public/javascripts'
|
||||
group 'javascript'
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
version=$JQUERY_VERSION_NUMBER
|
||||
else
|
||||
version="$1"
|
||||
fi
|
||||
curl -o public/javascripts/jquery.js "http://ajax.googleapis.com/ajax/libs/jquery/$version/jquery.min.js"
|
||||
}
|
||||
|
||||
function jquery_ui_install {
|
||||
about 'download jquery_us.js into public/javascripts'
|
||||
group 'javascript'
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
version=$JQUERY_UI_VERSION_NUMBER
|
||||
else
|
||||
version="$1"
|
||||
fi
|
||||
|
||||
curl -o public/javascripts/jquery_ui.js "http://ajax.googleapis.com/ajax/libs/jqueryui/$version/jquery-ui.min.js"
|
||||
}
|
||||
288
dot_bash_it/plugins/available/jekyll.plugin.bash
Normal file
288
dot_bash_it/plugins/available/jekyll.plugin.bash
Normal file
@@ -0,0 +1,288 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'manage your jekyll site'
|
||||
|
||||
function editpost() {
|
||||
about 'edit a post'
|
||||
param '1: site directory'
|
||||
group 'jekyll'
|
||||
|
||||
local SITE site POST DATE TITLE POSTS
|
||||
local -i COUNTER=1 POST_TO_EDIT ret
|
||||
if [[ -z "${1:-}" ]]; then
|
||||
echo "Error: no site specified."
|
||||
echo "The site is the name of the directory your project is in."
|
||||
return 1
|
||||
fi
|
||||
|
||||
for site in "${SITES[@]:-}"; do
|
||||
if [[ "${site##*/}" == "$1" ]]; then
|
||||
SITE="${site}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${SITE:-}" ]]; then
|
||||
echo "No such site."
|
||||
return 1
|
||||
fi
|
||||
|
||||
pushd "${SITE}/_posts" > /dev/null || return
|
||||
|
||||
for POST in *; do
|
||||
DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
|
||||
TITLE="$(grep -oE "title: (.+)" < "${POST}")"
|
||||
TITLE="${TITLE/title: /}"
|
||||
echo "${COUNTER}) ${DATE} ${TITLE}"
|
||||
POSTS[COUNTER]="$POST"
|
||||
COUNTER="$((COUNTER + 1))"
|
||||
done > >(less)
|
||||
read -rp "Number of post to edit: " POST_TO_EDIT
|
||||
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[POST_TO_EDIT]}"
|
||||
ret="$?"
|
||||
popd > /dev/null || return "$ret"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
function newpost() {
|
||||
about 'create a new post'
|
||||
param '1: site directory'
|
||||
group 'jekyll'
|
||||
|
||||
local SITE site FNAME_POST_TITLE FNAME YAML_DATE
|
||||
local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
|
||||
local -i loc=0 ret
|
||||
if [[ -z "${1:-}" ]]; then
|
||||
echo "Error: no site specified."
|
||||
echo "The site is the name of the directory your project is in."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "${SITE}" ]]; then
|
||||
echo "No such site."
|
||||
return 1
|
||||
fi
|
||||
|
||||
for site in "${SITES[@]}"; do
|
||||
if [[ "${site##*/}" == "$1" ]]; then
|
||||
SITE="$site"
|
||||
JEKYLL_FORMATTING="${MARKUPS[loc]}"
|
||||
break
|
||||
fi
|
||||
loc=$((loc + 1))
|
||||
done
|
||||
|
||||
# Change directory into the local jekyll root
|
||||
pushd "${SITE}/_posts" > /dev/null || return
|
||||
|
||||
# Get the date for the new post's filename
|
||||
FNAME_DATE="$(date "+%Y-%m-%d")"
|
||||
|
||||
# If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
|
||||
OPTIONS=('Text' 'Quote' 'Image' 'Audio' 'Video' 'Link')
|
||||
|
||||
if [[ $JEKYLL_FORMATTING == "markdown" || $JEKYLL_FORMATTING == "textile" ]]; then
|
||||
select OPTION in "${OPTIONS[@]}"; do
|
||||
POST_TYPE="${OPTION}"
|
||||
break
|
||||
done
|
||||
fi
|
||||
|
||||
# Get the title for the new post
|
||||
read -rp "Enter title of the new post: " POST_TITLE
|
||||
|
||||
# Convert the spaces in the title to hyphens for use in the filename
|
||||
FNAME_POST_TITLE="${POST_TITLE/ /-}"
|
||||
|
||||
# Now, put it all together for the full filename
|
||||
FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
|
||||
|
||||
# And, finally, create the actual post file. But we're not done yet...
|
||||
{
|
||||
# Write a little stuff to the file for the YAML Front Matter
|
||||
echo "---"
|
||||
|
||||
# Now we have to get the date, again. But this time for in the header (YAML Front Matter) of the file
|
||||
YAML_DATE="$(date "+%B %d %Y %X")"
|
||||
|
||||
# Echo the YAML Formatted date to the post file
|
||||
echo "date: $YAML_DATE"
|
||||
|
||||
# Echo the original post title to the YAML Front Matter header
|
||||
echo "title: $POST_TITLE"
|
||||
|
||||
# And, now, echo the "post" layout to the YAML Front Matter header
|
||||
echo "layout: post"
|
||||
|
||||
# Close the YAML Front Matter Header
|
||||
echo "---"
|
||||
|
||||
echo
|
||||
} > "${FNAME}"
|
||||
|
||||
# Generate template text based on the post type
|
||||
if [[ $JEKYLL_FORMATTING == "markdown" ]]; then
|
||||
case $POST_TYPE in
|
||||
"Text")
|
||||
true
|
||||
;;
|
||||
"Quote")
|
||||
echo "> Quote"
|
||||
echo
|
||||
echo "— Author"
|
||||
;;
|
||||
"Image")
|
||||
echo ""
|
||||
;;
|
||||
"Audio")
|
||||
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
|
||||
;;
|
||||
"Video")
|
||||
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
|
||||
;;
|
||||
"Link")
|
||||
echo "[link][1]"
|
||||
echo
|
||||
echo "> Quote"
|
||||
echo
|
||||
echo "[1]: url"
|
||||
;;
|
||||
esac
|
||||
elif [[ $JEKYLL_FORMATTING == "textile" ]]; then
|
||||
case $POST_TYPE in
|
||||
"Text")
|
||||
true
|
||||
;;
|
||||
"Quote")
|
||||
echo "bq. Quote"
|
||||
echo
|
||||
echo "— Author"
|
||||
;;
|
||||
"Image")
|
||||
echo "!url(alt text)"
|
||||
;;
|
||||
"Audio")
|
||||
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
|
||||
;;
|
||||
"Video")
|
||||
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
|
||||
;;
|
||||
"Link")
|
||||
echo "\"Site\":url"
|
||||
echo
|
||||
echo "bq. Quote"
|
||||
;;
|
||||
esac
|
||||
fi >> "${FNAME}"
|
||||
|
||||
# Open the file in your favorite editor
|
||||
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${FNAME}"
|
||||
ret="$?"
|
||||
popd > /dev/null || return "$ret"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
function testsite() {
|
||||
about 'launches local jekyll server'
|
||||
param '1: site directory'
|
||||
group 'jekyll'
|
||||
|
||||
local SITE site
|
||||
local -i ret
|
||||
if [[ -z "${1:-}" ]]; then
|
||||
echo "Error: no site specified."
|
||||
echo "The site is the name of the directory your project is in."
|
||||
return 1
|
||||
fi
|
||||
|
||||
for site in "${SITES[@]}"; do
|
||||
if [[ "${site##*/}" == "$1" ]]; then
|
||||
SITE="$site"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${SITE}" ]]; then
|
||||
echo "No such site."
|
||||
return 1
|
||||
fi
|
||||
|
||||
pushd "${SITE}" > /dev/null || return
|
||||
jekyll --server --auto
|
||||
ret="$?"
|
||||
popd > /dev/null || return "$ret"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
function buildsite() {
|
||||
about 'builds site'
|
||||
param '1: site directory'
|
||||
group 'jekyll'
|
||||
|
||||
local SITE site
|
||||
local -i ret
|
||||
if [[ -z "${1:-}" ]]; then
|
||||
echo "Error: no site specified."
|
||||
echo "The site is the name of the directory your project is in."
|
||||
return 1
|
||||
fi
|
||||
|
||||
for site in "${SITES[@]}"; do
|
||||
if [[ "${site##*/}" == "$1" ]]; then
|
||||
SITE="$site"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${SITE}" ]]; then
|
||||
echo "No such site."
|
||||
return 1
|
||||
fi
|
||||
|
||||
pushd "${SITE}" > /dev/null || return
|
||||
rm -rf _site
|
||||
jekyll --no-server
|
||||
ret="$?"
|
||||
popd > /dev/null || return "$ret"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
function deploysite() {
|
||||
about 'rsyncs site to remote host'
|
||||
param '1: site directory'
|
||||
group 'jekyll'
|
||||
|
||||
local SITE site REMOTE
|
||||
local -i loc=0 ret
|
||||
if [[ -z "${1:-}" ]]; then
|
||||
echo "Error: no site specified."
|
||||
echo "The site is the name of the directory your project is in."
|
||||
return 1
|
||||
fi
|
||||
|
||||
for site in "${SITES[@]}"; do
|
||||
if [[ "${site##*/}" == "$1" ]]; then
|
||||
SITE="$site"
|
||||
# shellcheck disable=SC2153 # who knows
|
||||
REMOTE="${REMOTES[loc]}"
|
||||
break
|
||||
fi
|
||||
loc=$((loc + 1))
|
||||
done
|
||||
|
||||
if [[ -z "${SITE}" ]]; then
|
||||
echo "No such site."
|
||||
return 1
|
||||
fi
|
||||
|
||||
pushd "${SITE}" > /dev/null || return
|
||||
rsync -rz "${REMOTE?}"
|
||||
ret="$?"
|
||||
popd > /dev/null || return "$ret"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
# Load the Jekyll config
|
||||
if [[ -s "$HOME/.jekyllconfig" ]]; then
|
||||
source "$HOME/.jekyllconfig"
|
||||
fi
|
||||
22
dot_bash_it/plugins/available/jenv.plugin.bash
Normal file
22
dot_bash_it/plugins/available/jenv.plugin.bash
Normal file
@@ -0,0 +1,22 @@
|
||||
cite about-plugin
|
||||
about-plugin 'load jenv, if you are using it'
|
||||
|
||||
# Don't modify the environment if we can't find the tool:
|
||||
# - Check if in $PATH already
|
||||
# - Check if installed manually to $JENV_ROOT
|
||||
# - Check if installed manually to $HOME
|
||||
_command_exists jenv ||
|
||||
[[ -n "$JENV_ROOT" && -x "$JENV_ROOT/bin/jenv" ]] ||
|
||||
[[ -x "$HOME/.jenv/bin/jenv" ]] ||
|
||||
return
|
||||
|
||||
# Set JENV_ROOT, if not already set
|
||||
export JENV_ROOT="${JENV_ROOT:-$HOME/.jenv}"
|
||||
|
||||
# Add JENV_ROOT/bin to PATH, if that's where it's installed
|
||||
! _command_exists jenv &&
|
||||
[[ -x "$JENV_ROOT/bin/jenv" ]] &&
|
||||
pathmunge "$JENV_ROOT/bin"
|
||||
|
||||
# Initialize jenv
|
||||
eval "$(jenv init - bash)"
|
||||
47
dot_bash_it/plugins/available/jgitflow.plugin.bash
Normal file
47
dot_bash_it/plugins/available/jgitflow.plugin.bash
Normal file
@@ -0,0 +1,47 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Maven jgitflow build helpers'
|
||||
|
||||
function hotfix-start {
|
||||
about 'helper function for starting a new hotfix'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS}
|
||||
}
|
||||
|
||||
function hotfix-finish {
|
||||
about 'helper function for finishing a hotfix'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags
|
||||
}
|
||||
|
||||
function feature-start {
|
||||
about 'helper function for starting a new feature'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS}
|
||||
}
|
||||
|
||||
function feature-finish {
|
||||
about 'helper function for finishing a feature'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:feature-finish ${JGITFLOW_MVN_ARGUMENTS}
|
||||
echo -e '\033[32m----------------------------------------------------------------\033[0m'
|
||||
echo -e '\033[32m===== REMEMBER TO CREATE A NEW RELEASE TO DEPLOY THIS FEATURE ====\033[0m'
|
||||
echo -e '\033[32m----------------------------------------------------------------\033[0m'
|
||||
}
|
||||
|
||||
function release-start {
|
||||
about 'helper function for starting a new release'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:release-start ${JGITFLOW_MVN_ARGUMENTS}
|
||||
}
|
||||
|
||||
function release-finish {
|
||||
about 'helper function for finishing a release'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:release-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags
|
||||
}
|
||||
12
dot_bash_it/plugins/available/jump.plugin.bash
Normal file
12
dot_bash_it/plugins/available/jump.plugin.bash
Normal file
@@ -0,0 +1,12 @@
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
cite about-plugin
|
||||
about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding'
|
||||
|
||||
function __init_jump() {
|
||||
if _command_exists jump; then
|
||||
eval "$(jump shell bash "${JUMP_OPTS[@]}")"
|
||||
fi
|
||||
}
|
||||
|
||||
__init_jump
|
||||
19
dot_bash_it/plugins/available/latex.plugin.bash
Normal file
19
dot_bash_it/plugins/available/latex.plugin.bash
Normal file
@@ -0,0 +1,19 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'add MacTeX to PATH'
|
||||
|
||||
_bash_it_plugin_latex_paths=(
|
||||
# Standard locations
|
||||
/usr/local/texbin
|
||||
# MacOS locations
|
||||
/Library/TeX/texbin
|
||||
)
|
||||
|
||||
# add mactex to the path if its present
|
||||
for _bash_it_plugin_latex_path in "${_bash_it_plugin_latex_paths[@]}"; do
|
||||
if [[ -d "$_bash_it_plugin_latex_path/" ]]; then
|
||||
pathmunge "$_bash_it_plugin_latex_path" after && break
|
||||
fi
|
||||
done
|
||||
|
||||
# Cleanup
|
||||
unset "${!_bash_it_plugin_latex_@}"
|
||||
23
dot_bash_it/plugins/available/less-pretty-cat.plugin.bash
Normal file
23
dot_bash_it/plugins/available/less-pretty-cat.plugin.bash
Normal file
@@ -0,0 +1,23 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'pygmentize instead of cat to terminal if possible'
|
||||
|
||||
_command_exists pygmentize || return
|
||||
|
||||
# pigmentize cat and less outputs - call them ccat and cless to avoid that
|
||||
# especially cat'ed output in scripts gets mangled with pygemtized meta characters
|
||||
function ccat() {
|
||||
about 'runs pygmentize on each file passed in'
|
||||
param '*: files to concatenate (as normally passed to cat)'
|
||||
example 'ccat mysite/manage.py dir/text-file.txt'
|
||||
|
||||
pygmentize -f 256 -O style="${BASH_IT_CCAT_STYLE:-default}" -g "$@"
|
||||
}
|
||||
|
||||
function cless() {
|
||||
about 'pigments the files passed in and passes to less for pagination'
|
||||
param '*: the files to paginate with less'
|
||||
example 'cless mysite/manage.py'
|
||||
|
||||
pygmentize -f 256 -O style="${BASH_IT_CLESS_STYLE:-default}" -g "$@" | command less -R
|
||||
}
|
||||
14
dot_bash_it/plugins/available/man.plugin.bash
Normal file
14
dot_bash_it/plugins/available/man.plugin.bash
Normal file
@@ -0,0 +1,14 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'colorize man pages for better readability'
|
||||
|
||||
: "${LESS_TERMCAP_mb:=$'\e[1;32m'}"
|
||||
: "${LESS_TERMCAP_md:=$'\e[1;32m'}"
|
||||
: "${LESS_TERMCAP_me:=$'\e[0m'}"
|
||||
: "${LESS_TERMCAP_se:=$'\e[0m'}"
|
||||
: "${LESS_TERMCAP_so:=$'\e[01;33m'}"
|
||||
: "${LESS_TERMCAP_ue:=$'\e[0m'}"
|
||||
: "${LESS_TERMCAP_us:=$'\e[1;4;31m'}"
|
||||
|
||||
: "${LESS:=}"
|
||||
export "${!LESS_TERMCAP@}"
|
||||
export LESS="R${LESS#-}"
|
||||
55
dot_bash_it/plugins/available/nginx.plugin.bash
Normal file
55
dot_bash_it/plugins/available/nginx.plugin.bash
Normal file
@@ -0,0 +1,55 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'manage your nginx service'
|
||||
|
||||
pathmunge "${NGINX_PATH:=/opt/nginx}/sbin" after
|
||||
export NGINX_PATH
|
||||
|
||||
function nginx_reload() {
|
||||
about 'reload your nginx config'
|
||||
group 'nginx'
|
||||
|
||||
local FILE="${NGINX_PATH?}/logs/nginx.pid"
|
||||
if [[ -s $FILE ]]; then
|
||||
echo "Reloading NGINX..."
|
||||
read -r PID < "${FILE}"
|
||||
sudo kill -HUP "${PID?}"
|
||||
else
|
||||
echo "Nginx pid file not found"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function nginx_stop() {
|
||||
about 'stop nginx'
|
||||
group 'nginx'
|
||||
|
||||
local FILE="${NGINX_PATH?}/logs/nginx.pid"
|
||||
if [[ -s $FILE ]]; then
|
||||
echo "Stopping NGINX..."
|
||||
read -r PID < "${FILE}"
|
||||
sudo kill -INT "${PID?}"
|
||||
else
|
||||
echo "Nginx pid file not found"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function nginx_start() {
|
||||
about 'start nginx'
|
||||
group 'nginx'
|
||||
|
||||
local FILE="${NGINX_PATH?}/sbin/nginx"
|
||||
if [[ -x $FILE ]]; then
|
||||
echo "Starting NGINX..."
|
||||
sudo "${FILE}"
|
||||
else
|
||||
echo "Couldn't start nginx"
|
||||
fi
|
||||
}
|
||||
|
||||
function nginx_restart() {
|
||||
about 'restart nginx'
|
||||
group 'nginx'
|
||||
|
||||
nginx_stop && nginx_start
|
||||
}
|
||||
14
dot_bash_it/plugins/available/node.plugin.bash
Normal file
14
dot_bash_it/plugins/available/node.plugin.bash
Normal file
@@ -0,0 +1,14 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Node.js helper functions'
|
||||
|
||||
# Check that we have npm
|
||||
_command_exists npm || return
|
||||
|
||||
# Ensure local modules are preferred in PATH
|
||||
pathmunge "./node_modules/.bin" "after"
|
||||
|
||||
# If not using nodenv, ensure global modules are in PATH
|
||||
if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then
|
||||
pathmunge "$(npm config get prefix)/bin" "after"
|
||||
fi
|
||||
10
dot_bash_it/plugins/available/nodenv.plugin.bash
Normal file
10
dot_bash_it/plugins/available/nodenv.plugin.bash
Normal file
@@ -0,0 +1,10 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load nodenv, if you are using it'
|
||||
|
||||
export NODENV_ROOT="$HOME/.nodenv"
|
||||
pathmunge "$NODENV_ROOT/bin"
|
||||
|
||||
if _command_exists nodenv; then
|
||||
eval "$(nodenv init - bash)"
|
||||
fi
|
||||
31
dot_bash_it/plugins/available/nvm.plugin.bash
Normal file
31
dot_bash_it/plugins/available/nvm.plugin.bash
Normal file
@@ -0,0 +1,31 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# BASH_IT_LOAD_PRIORITY: 225
|
||||
#
|
||||
# Bash-it no longer bundles nvm, as this was quickly becoming outdated.
|
||||
# Please install nvm from https://github.com/creationix/nvm.git if you want to use it.
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'node version manager configuration'
|
||||
|
||||
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
|
||||
# This loads nvm
|
||||
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]]
|
||||
then
|
||||
source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh"
|
||||
else
|
||||
[[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
|
||||
fi
|
||||
|
||||
if ! _command_exists nvm
|
||||
then
|
||||
function nvm() {
|
||||
echo "Bash-it no longer bundles the nvm script. Please install the latest version from"
|
||||
echo ""
|
||||
echo "https://github.com/creationix/nvm.git"
|
||||
echo ""
|
||||
echo "if you want to use nvm. You can keep this plugin enabled once you have installed nvm."
|
||||
}
|
||||
|
||||
nvm
|
||||
fi
|
||||
95
dot_bash_it/plugins/available/osx-timemachine.plugin.bash
Normal file
95
dot_bash_it/plugins/available/osx-timemachine.plugin.bash
Normal file
@@ -0,0 +1,95 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'OS X Time Machine functions'
|
||||
|
||||
if [[ "${OSTYPE}" != 'darwin'* ]]; then
|
||||
_log_warning "This plugin only works with Mac OS X"
|
||||
return 1
|
||||
fi
|
||||
|
||||
function time-machine-destination() {
|
||||
group "osx-timemachine"
|
||||
about "Shows the OS X Time Machine destination/mount point"
|
||||
|
||||
tmutil destinationinfo | grep "Mount Point" | sed -e 's/Mount Point : \(.*\)/\1/g'
|
||||
}
|
||||
|
||||
function time-machine-list-machines() {
|
||||
group "osx-timemachine"
|
||||
about "Lists the OS X Time Machine machines on the backup volume"
|
||||
|
||||
local tmdest
|
||||
tmdest="$(time-machine-destination)/Backups.backupdb"
|
||||
|
||||
find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read -r line; do
|
||||
echo "${line##*/}"
|
||||
done
|
||||
}
|
||||
|
||||
function time-machine-list-all-backups() {
|
||||
group "osx-timemachine"
|
||||
about "Shows all of the backups for the specified machine"
|
||||
param "1: Machine name (optional)"
|
||||
example "time-machine-list-all-backups my-laptop"
|
||||
|
||||
# Use the local hostname if none provided
|
||||
local COMPUTERNAME BACKUP_LOCATION
|
||||
COMPUTERNAME=${1:-$(scutil --get ComputerName)}
|
||||
BACKUP_LOCATION="$(time-machine-destination)/Backups.backupdb/$COMPUTERNAME"
|
||||
|
||||
find "$BACKUP_LOCATION" -maxdepth 1 -mindepth 1 -type d | while read -r line; do
|
||||
echo "$line"
|
||||
done
|
||||
}
|
||||
|
||||
function time-machine-list-old-backups() {
|
||||
group "osx-timemachine"
|
||||
about "Shows all of the backups for the specified machine, except for the most recent backup"
|
||||
param "1: Machine name (optional)"
|
||||
example "time-machine-list-old-backups my-laptop"
|
||||
|
||||
# Use the local hostname if none provided
|
||||
local COMPUTERNAME BACKUP_LOCATION
|
||||
COMPUTERNAME=${1:-$(scutil --get ComputerName)}
|
||||
BACKUP_LOCATION="$(time-machine-destination)/Backups.backupdb/$COMPUTERNAME"
|
||||
|
||||
# List all but the most recent one
|
||||
find "$BACKUP_LOCATION" -maxdepth 1 -mindepth 1 -type d -name 2\* | sed \$d | while read -r line; do
|
||||
echo "$line"
|
||||
done
|
||||
}
|
||||
|
||||
# Taken from here: http://stackoverflow.com/a/30547074/1228454
|
||||
function _tm_startsudo() {
|
||||
local -x SUDO_COMMAND="plugin/osx-timemachine: keep 'sudo' token alive during long-run 'tmutil' commands"
|
||||
sudo "-${SUDO_ASKPASS:+A}v" # validate without running a command, using `ssh-askpass` if available.
|
||||
(while sudo "-${SUDO_ASKPASS:+A}v"; do
|
||||
sleep 50
|
||||
done) &
|
||||
SUDO_PID="$!"
|
||||
trap _tm_stopsudo SIGINT SIGTERM
|
||||
}
|
||||
function _tm_stopsudo() {
|
||||
kill "$SUDO_PID"
|
||||
trap - SIGINT SIGTERM
|
||||
sudo -k
|
||||
}
|
||||
|
||||
function time-machine-delete-old-backups() {
|
||||
group "osx-timemachine"
|
||||
about "Deletes all of the backups for the specified machine, with the exception of the most recent one"
|
||||
param "1: Machine name (optional)"
|
||||
example "time-machine-delete-old-backups my-laptop"
|
||||
|
||||
# Use the local hostname if none provided
|
||||
local COMPUTERNAME=${1:-$(scutil --get ComputerName)} _old_backup
|
||||
|
||||
# Ask for sudo credentials only once
|
||||
_tm_startsudo
|
||||
|
||||
while read -r _old_backup; do
|
||||
# Delete the backup
|
||||
sudo tmutil delete "$_old_backup"
|
||||
done <<< "$(time-machine-list-old-backups "$COMPUTERNAME")"
|
||||
|
||||
_tm_stopsudo
|
||||
}
|
||||
132
dot_bash_it/plugins/available/osx.plugin.bash
Normal file
132
dot_bash_it/plugins/available/osx.plugin.bash
Normal file
@@ -0,0 +1,132 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'osx-specific functions'
|
||||
|
||||
if [[ "${OSTYPE}" != 'darwin'* ]]; then
|
||||
_log_warning "This plugin only works with Mac OS X."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# OS X: Open new tabs in same directory
|
||||
if _is_function update_terminal_cwd; then
|
||||
safe_append_prompt_command 'update_terminal_cwd'
|
||||
fi
|
||||
|
||||
function tab() {
|
||||
about 'opens a new terminal tab'
|
||||
group 'osx'
|
||||
|
||||
osascript 2> /dev/null << EOF
|
||||
tell application "System Events"
|
||||
tell process "Terminal" to keystroke "t" using command down
|
||||
end
|
||||
tell application "Terminal"
|
||||
activate
|
||||
do script with command " cd \"$PWD\"; $*" in window 0
|
||||
end tell
|
||||
EOF
|
||||
}
|
||||
|
||||
# renames the current os x terminal tab title
|
||||
function tabname {
|
||||
printf '%b' "\e]1;$1\a"
|
||||
}
|
||||
|
||||
# renames the current os x terminal window title
|
||||
function winname {
|
||||
printf '%b' "\e]2;$1\a"
|
||||
}
|
||||
|
||||
function pman() {
|
||||
about 'view man documentation in Preview'
|
||||
param '1: man page to view'
|
||||
example '$ pman bash'
|
||||
group 'osx'
|
||||
man -t "${1}" | open -fa 'Preview'
|
||||
}
|
||||
|
||||
function pri() {
|
||||
about 'display information about Ruby classes, modules, or methods, in Preview'
|
||||
param '1: Ruby method, module, or class'
|
||||
example '$ pri Array'
|
||||
group 'osx'
|
||||
ri -T "${1}" | open -fa 'Preview'
|
||||
}
|
||||
|
||||
# Download a file and open it in Preview
|
||||
function prevcurl() {
|
||||
about 'download a file and open it in Preview'
|
||||
param '1: url'
|
||||
group 'osx'
|
||||
|
||||
curl "$*" | open -fa 'Preview'
|
||||
}
|
||||
|
||||
function refresh-launchpad() {
|
||||
about 'Reset launchpad layout in macOS'
|
||||
example '$ refresh-launchpad'
|
||||
group 'osx'
|
||||
|
||||
defaults write com.apple.dock ResetLaunchPad -bool TRUE
|
||||
killall Dock
|
||||
}
|
||||
|
||||
function list-jvms() {
|
||||
about 'List java virtual machines and their states in macOS'
|
||||
example 'list-jvms'
|
||||
group 'osx'
|
||||
|
||||
local JVMS_DIR="/Library/Java/JavaVirtualMachines"
|
||||
# The following variables are intended to impact the enclosing scope, not local.
|
||||
JVMS=("${JVMS_DIR}"/*)
|
||||
JVMS_STATES=()
|
||||
|
||||
# Map state of JVM
|
||||
for ((i = 0; i < ${#JVMS[@]}; i++)); do
|
||||
if [[ -f "${JVMS[i]}/Contents/Info.plist" ]]; then
|
||||
JVMS_STATES[i]=enabled
|
||||
else
|
||||
JVMS_STATES[i]=disabled
|
||||
fi
|
||||
printf '%s\t%s\t%s\n' "${i}" "${JVMS[i]##*/}" "${JVMS_STATES[i]}"
|
||||
done
|
||||
}
|
||||
|
||||
function pick-default-jvm() {
|
||||
about 'Pick the default Java Virtual Machines in system-wide scope in macOS'
|
||||
example 'pick-default-jvm'
|
||||
|
||||
# Declare variables
|
||||
local JVMS JVMS_STATES
|
||||
local DEFAULT_JVM_DIR DEFAULT_JVM OPTION
|
||||
|
||||
# Call function for listing
|
||||
list-jvms
|
||||
|
||||
# OPTION for default jdk and set variables
|
||||
while [[ ! "$OPTION" =~ ^[0-9]+$ || OPTION -ge "${#JVMS[@]}" ]]; do
|
||||
read -rp "Enter Default JVM: " OPTION
|
||||
if [[ ! "$OPTION" =~ ^[0-9]+$ ]]; then
|
||||
echo "Please enter a number"
|
||||
fi
|
||||
|
||||
if [[ OPTION -ge "${#JVMS[@]}" ]]; then
|
||||
echo "Please select one of the displayed JVMs"
|
||||
fi
|
||||
done
|
||||
|
||||
DEFAULT_JVM_DIR="${JVMS[OPTION]}"
|
||||
DEFAULT_JVM="${JVMS[OPTION]##*/}"
|
||||
|
||||
# Disable all jdk
|
||||
for ((i = 0; i < ${#JVMS[@]}; i++)); do
|
||||
if [[ "${JVMS[i]}" != "${DEFAULT_JVM_DIR}" && -f "${JVMS[i]}/Contents/Info.plist" ]]; then
|
||||
sudo mv "${JVMS[i]}/Contents/Info.plist" "${JVMS[i]}/Contents/Info.plist.disable"
|
||||
fi
|
||||
done
|
||||
|
||||
# Enable default jdk
|
||||
if [[ -f "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" ]]; then
|
||||
sudo mv -vn "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" "${DEFAULT_JVM_DIR}/Contents/Info.plist" \
|
||||
&& echo "Enabled ${DEFAULT_JVM} as default JVM"
|
||||
fi
|
||||
}
|
||||
621
dot_bash_it/plugins/available/pack.plugin.bash
Normal file
621
dot_bash_it/plugins/available/pack.plugin.bash
Normal file
@@ -0,0 +1,621 @@
|
||||
# bash completion for pack -*- shell-script -*-
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'CNB pack cli aliases'
|
||||
|
||||
|
||||
__pack_debug()
|
||||
{
|
||||
if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
|
||||
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Homebrew on Macs have version 1.3 of bash-completion which doesn't include
|
||||
# _init_completion. This is a very minimal version of that function.
|
||||
__pack_init_completion()
|
||||
{
|
||||
COMPREPLY=()
|
||||
_get_comp_words_by_ref "$@" cur prev words cword
|
||||
}
|
||||
|
||||
__pack_index_of_word()
|
||||
{
|
||||
local w word=$1
|
||||
shift
|
||||
index=0
|
||||
for w in "$@"; do
|
||||
[[ $w = "$word" ]] && return
|
||||
index=$((index+1))
|
||||
done
|
||||
index=-1
|
||||
}
|
||||
|
||||
__pack_contains_word()
|
||||
{
|
||||
local w word=$1; shift
|
||||
for w in "$@"; do
|
||||
[[ $w = "$word" ]] && return
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
__pack_handle_reply()
|
||||
{
|
||||
__pack_debug "${FUNCNAME[0]}"
|
||||
case $cur in
|
||||
-*)
|
||||
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||
compopt -o nospace
|
||||
fi
|
||||
local allflags
|
||||
if [ ${#must_have_one_flag[@]} -ne 0 ]; then
|
||||
allflags=("${must_have_one_flag[@]}")
|
||||
else
|
||||
allflags=("${flags[*]} ${two_word_flags[*]}")
|
||||
fi
|
||||
COMPREPLY=( $(compgen -W "${allflags[*]}" -- "$cur") )
|
||||
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||
[[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace
|
||||
fi
|
||||
|
||||
# complete after --flag=abc
|
||||
if [[ $cur == *=* ]]; then
|
||||
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||
compopt +o nospace
|
||||
fi
|
||||
|
||||
local index flag
|
||||
flag="${cur%=*}"
|
||||
__pack_index_of_word "${flag}" "${flags_with_completion[@]}"
|
||||
COMPREPLY=()
|
||||
if [[ ${index} -ge 0 ]]; then
|
||||
PREFIX=""
|
||||
cur="${cur#*=}"
|
||||
${flags_completion[${index}]}
|
||||
if [ -n "${ZSH_VERSION}" ]; then
|
||||
# zsh completion needs --flag= prefix
|
||||
eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
return 0;
|
||||
;;
|
||||
esac
|
||||
|
||||
# check if we are handling a flag with special work handling
|
||||
local index
|
||||
__pack_index_of_word "${prev}" "${flags_with_completion[@]}"
|
||||
if [[ ${index} -ge 0 ]]; then
|
||||
${flags_completion[${index}]}
|
||||
return
|
||||
fi
|
||||
|
||||
# we are parsing a flag and don't have a special handler, no completion
|
||||
if [[ ${cur} != "${words[cword]}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local completions
|
||||
completions=("${commands[@]}")
|
||||
if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
|
||||
completions=("${must_have_one_noun[@]}")
|
||||
fi
|
||||
if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then
|
||||
completions+=("${must_have_one_flag[@]}")
|
||||
fi
|
||||
COMPREPLY=( $(compgen -W "${completions[*]}" -- "$cur") )
|
||||
|
||||
if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then
|
||||
COMPREPLY=( $(compgen -W "${noun_aliases[*]}" -- "$cur") )
|
||||
fi
|
||||
|
||||
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
|
||||
declare -F __custom_func >/dev/null && __custom_func
|
||||
fi
|
||||
|
||||
# available in bash-completion >= 2, not always present on macOS
|
||||
if declare -F __ltrim_colon_completions >/dev/null; then
|
||||
__ltrim_colon_completions "$cur"
|
||||
fi
|
||||
|
||||
# If there is only 1 completion and it is a flag with an = it will be completed
|
||||
# but we don't want a space after the =
|
||||
if [[ "${#COMPREPLY[@]}" -eq "1" ]] && [[ $(type -t compopt) = "builtin" ]] && [[ "${COMPREPLY[0]}" == --*= ]]; then
|
||||
compopt -o nospace
|
||||
fi
|
||||
}
|
||||
|
||||
# The arguments should be in the form "ext1|ext2|extn"
|
||||
__pack_handle_filename_extension_flag()
|
||||
{
|
||||
local ext="$1"
|
||||
_filedir "@(${ext})"
|
||||
}
|
||||
|
||||
__pack_handle_subdirs_in_dir_flag()
|
||||
{
|
||||
local dir="$1"
|
||||
pushd "${dir}" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1
|
||||
}
|
||||
|
||||
__pack_handle_flag()
|
||||
{
|
||||
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
|
||||
# if a command required a flag, and we found it, unset must_have_one_flag()
|
||||
local flagname=${words[c]}
|
||||
local flagvalue
|
||||
# if the word contained an =
|
||||
if [[ ${words[c]} == *"="* ]]; then
|
||||
flagvalue=${flagname#*=} # take in as flagvalue after the =
|
||||
flagname=${flagname%=*} # strip everything after the =
|
||||
flagname="${flagname}=" # but put the = back
|
||||
fi
|
||||
__pack_debug "${FUNCNAME[0]}: looking for ${flagname}"
|
||||
if __pack_contains_word "${flagname}" "${must_have_one_flag[@]}"; then
|
||||
must_have_one_flag=()
|
||||
fi
|
||||
|
||||
# if you set a flag which only applies to this command, don't show subcommands
|
||||
if __pack_contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then
|
||||
commands=()
|
||||
fi
|
||||
|
||||
# keep flag value with flagname as flaghash
|
||||
# flaghash variable is an associative array which is only supported in bash > 3.
|
||||
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
|
||||
if [ -n "${flagvalue}" ] ; then
|
||||
flaghash[${flagname}]=${flagvalue}
|
||||
elif [ -n "${words[ $((c+1)) ]}" ] ; then
|
||||
flaghash[${flagname}]=${words[ $((c+1)) ]}
|
||||
else
|
||||
flaghash[${flagname}]="true" # pad "true" for bool flag
|
||||
fi
|
||||
fi
|
||||
|
||||
# skip the argument to a two word flag
|
||||
if __pack_contains_word "${words[c]}" "${two_word_flags[@]}"; then
|
||||
c=$((c+1))
|
||||
# if we are looking for a flags value, don't show commands
|
||||
if [[ $c -eq $cword ]]; then
|
||||
commands=()
|
||||
fi
|
||||
fi
|
||||
|
||||
c=$((c+1))
|
||||
|
||||
}
|
||||
|
||||
__pack_handle_noun()
|
||||
{
|
||||
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
|
||||
if __pack_contains_word "${words[c]}" "${must_have_one_noun[@]}"; then
|
||||
must_have_one_noun=()
|
||||
elif __pack_contains_word "${words[c]}" "${noun_aliases[@]}"; then
|
||||
must_have_one_noun=()
|
||||
fi
|
||||
|
||||
nouns+=("${words[c]}")
|
||||
c=$((c+1))
|
||||
}
|
||||
|
||||
__pack_handle_command()
|
||||
{
|
||||
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
|
||||
local next_command
|
||||
if [[ -n ${last_command} ]]; then
|
||||
next_command="_${last_command}_${words[c]//:/__}"
|
||||
else
|
||||
if [[ $c -eq 0 ]]; then
|
||||
next_command="_pack_root_command"
|
||||
else
|
||||
next_command="_${words[c]//:/__}"
|
||||
fi
|
||||
fi
|
||||
c=$((c+1))
|
||||
__pack_debug "${FUNCNAME[0]}: looking for ${next_command}"
|
||||
declare -F "$next_command" >/dev/null && $next_command
|
||||
}
|
||||
|
||||
__pack_handle_word()
|
||||
{
|
||||
if [[ $c -ge $cword ]]; then
|
||||
__pack_handle_reply
|
||||
return
|
||||
fi
|
||||
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
if [[ "${words[c]}" == -* ]]; then
|
||||
__pack_handle_flag
|
||||
elif __pack_contains_word "${words[c]}" "${commands[@]}"; then
|
||||
__pack_handle_command
|
||||
elif [[ $c -eq 0 ]]; then
|
||||
__pack_handle_command
|
||||
elif __pack_contains_word "${words[c]}" "${command_aliases[@]}"; then
|
||||
# aliashash variable is an associative array which is only supported in bash > 3.
|
||||
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
|
||||
words[c]=${aliashash[${words[c]}]}
|
||||
__pack_handle_command
|
||||
else
|
||||
__pack_handle_noun
|
||||
fi
|
||||
else
|
||||
__pack_handle_noun
|
||||
fi
|
||||
__pack_handle_word
|
||||
}
|
||||
|
||||
_pack_build()
|
||||
{
|
||||
last_command="pack_build"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--builder=")
|
||||
local_nonpersistent_flags+=("--builder=")
|
||||
flags+=("--buildpack=")
|
||||
local_nonpersistent_flags+=("--buildpack=")
|
||||
flags+=("--clear-cache")
|
||||
local_nonpersistent_flags+=("--clear-cache")
|
||||
flags+=("--env=")
|
||||
two_word_flags+=("-e")
|
||||
local_nonpersistent_flags+=("--env=")
|
||||
flags+=("--env-file=")
|
||||
local_nonpersistent_flags+=("--env-file=")
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-pull")
|
||||
local_nonpersistent_flags+=("--no-pull")
|
||||
flags+=("--path=")
|
||||
two_word_flags+=("-p")
|
||||
local_nonpersistent_flags+=("--path=")
|
||||
flags+=("--publish")
|
||||
local_nonpersistent_flags+=("--publish")
|
||||
flags+=("--run-image=")
|
||||
local_nonpersistent_flags+=("--run-image=")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_run()
|
||||
{
|
||||
last_command="pack_run"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--builder=")
|
||||
local_nonpersistent_flags+=("--builder=")
|
||||
flags+=("--buildpack=")
|
||||
local_nonpersistent_flags+=("--buildpack=")
|
||||
flags+=("--clear-cache")
|
||||
local_nonpersistent_flags+=("--clear-cache")
|
||||
flags+=("--env=")
|
||||
two_word_flags+=("-e")
|
||||
local_nonpersistent_flags+=("--env=")
|
||||
flags+=("--env-file=")
|
||||
local_nonpersistent_flags+=("--env-file=")
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-pull")
|
||||
local_nonpersistent_flags+=("--no-pull")
|
||||
flags+=("--path=")
|
||||
two_word_flags+=("-p")
|
||||
local_nonpersistent_flags+=("--path=")
|
||||
flags+=("--port=")
|
||||
local_nonpersistent_flags+=("--port=")
|
||||
flags+=("--run-image=")
|
||||
local_nonpersistent_flags+=("--run-image=")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_rebase()
|
||||
{
|
||||
last_command="pack_rebase"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-pull")
|
||||
local_nonpersistent_flags+=("--no-pull")
|
||||
flags+=("--publish")
|
||||
local_nonpersistent_flags+=("--publish")
|
||||
flags+=("--run-image=")
|
||||
local_nonpersistent_flags+=("--run-image=")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_create-builder()
|
||||
{
|
||||
last_command="pack_create-builder"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--builder-config=")
|
||||
two_word_flags+=("-b")
|
||||
local_nonpersistent_flags+=("--builder-config=")
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-pull")
|
||||
local_nonpersistent_flags+=("--no-pull")
|
||||
flags+=("--publish")
|
||||
local_nonpersistent_flags+=("--publish")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_flag+=("--builder-config=")
|
||||
must_have_one_flag+=("-b")
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_set-run-image-mirrors()
|
||||
{
|
||||
last_command="pack_set-run-image-mirrors"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--mirror=")
|
||||
two_word_flags+=("-m")
|
||||
local_nonpersistent_flags+=("--mirror=")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_flag+=("--mirror=")
|
||||
must_have_one_flag+=("-m")
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_inspect-builder()
|
||||
{
|
||||
last_command="pack_inspect-builder"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_set-default-builder()
|
||||
{
|
||||
last_command="pack_set-default-builder"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_version()
|
||||
{
|
||||
last_command="pack_version"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_completion()
|
||||
{
|
||||
last_command="pack_completion"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
_pack_root_command()
|
||||
{
|
||||
last_command="pack"
|
||||
|
||||
command_aliases=()
|
||||
|
||||
commands=()
|
||||
commands+=("build")
|
||||
commands+=("run")
|
||||
commands+=("rebase")
|
||||
commands+=("create-builder")
|
||||
commands+=("set-run-image-mirrors")
|
||||
commands+=("inspect-builder")
|
||||
commands+=("set-default-builder")
|
||||
commands+=("version")
|
||||
commands+=("completion")
|
||||
|
||||
flags=()
|
||||
two_word_flags=()
|
||||
local_nonpersistent_flags=()
|
||||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--help")
|
||||
flags+=("-h")
|
||||
local_nonpersistent_flags+=("--help")
|
||||
flags+=("--no-color")
|
||||
flags+=("--quiet")
|
||||
flags+=("-q")
|
||||
flags+=("--timestamps")
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
noun_aliases=()
|
||||
}
|
||||
|
||||
__start_pack()
|
||||
{
|
||||
local cur prev words cword
|
||||
declare -A flaghash 2>/dev/null || :
|
||||
declare -A aliashash 2>/dev/null || :
|
||||
if declare -F _init_completion >/dev/null 2>&1; then
|
||||
_init_completion -s || return
|
||||
else
|
||||
__pack_init_completion -n "=" || return
|
||||
fi
|
||||
|
||||
local c=0
|
||||
local flags=()
|
||||
local two_word_flags=()
|
||||
local local_nonpersistent_flags=()
|
||||
local flags_with_completion=()
|
||||
local flags_completion=()
|
||||
local commands=("pack")
|
||||
local must_have_one_flag=()
|
||||
local must_have_one_noun=()
|
||||
local last_command
|
||||
local nouns=()
|
||||
|
||||
__pack_handle_word
|
||||
}
|
||||
|
||||
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||
complete -o default -F __start_pack pack
|
||||
else
|
||||
complete -o default -o nospace -F __start_pack pack
|
||||
fi
|
||||
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
32
dot_bash_it/plugins/available/percol.plugin.bash
Normal file
32
dot_bash_it/plugins/available/percol.plugin.bash
Normal file
@@ -0,0 +1,32 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Search&Select history with percol'
|
||||
|
||||
# Notice
|
||||
## You have to upgrade bash to bash 4.x on Mac OS X.
|
||||
## http://stackoverflow.com/questions/16416195/how-do-i-upgrade-bash-in-mac-osx-mountain-lion-and-set-it-the-correct-path
|
||||
|
||||
# Install
|
||||
## (sudo) pip install percol
|
||||
## bash-it enable percol
|
||||
|
||||
# Usage
|
||||
## C-r to search&select from history
|
||||
|
||||
_command_exists percol || return
|
||||
|
||||
if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then
|
||||
_log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin."
|
||||
_log_warning "Your current Bash version is $BASH_VERSION."
|
||||
return
|
||||
fi
|
||||
|
||||
function _replace_by_history() {
|
||||
local HISTTIMEFORMAT= # Ensure we can parse history properly
|
||||
#TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}"
|
||||
local l
|
||||
l="$(history | tail -r | sed -e 's/^\ *[0-9]*\ *//' | percol --query "${READLINE_LINE:-}")"
|
||||
READLINE_LINE="${l}"
|
||||
READLINE_POINT=${#l}
|
||||
}
|
||||
bind -x '"\C-r": _replace_by_history'
|
||||
7
dot_bash_it/plugins/available/pipsi.plugin.bash
Normal file
7
dot_bash_it/plugins/available/pipsi.plugin.bash
Normal file
@@ -0,0 +1,7 @@
|
||||
cite about-plugin
|
||||
about-plugin 'load pipsi, if you are using it'
|
||||
|
||||
if [[ -f "$HOME/.local/bin/pipsi" ]]
|
||||
then
|
||||
pathmunge ~/.local/bin
|
||||
fi
|
||||
16
dot_bash_it/plugins/available/plenv.plugin.bash
Normal file
16
dot_bash_it/plugins/available/plenv.plugin.bash
Normal file
@@ -0,0 +1,16 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# plugin for plenv
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'plenv plugin for Perl'
|
||||
|
||||
if [[ -d "${HOME}/.plenv/bin" ]]; then
|
||||
# load plenv bin dir into path if it exists
|
||||
pathmunge "${HOME}/.plenv/bin"
|
||||
fi
|
||||
|
||||
if _command_exists plenv; then
|
||||
# init plenv
|
||||
eval "$(plenv init - bash)"
|
||||
fi
|
||||
86
dot_bash_it/plugins/available/postgres.plugin.bash
Normal file
86
dot_bash_it/plugins/available/postgres.plugin.bash
Normal file
@@ -0,0 +1,86 @@
|
||||
cite about-plugin
|
||||
about-plugin 'postgres helper functions'
|
||||
|
||||
|
||||
export PGVERSION=`pg_config --version | awk '{print $2}'`
|
||||
export POSTGRES_BIN=`pg_config --bindir`
|
||||
COMMON_PGDATA_PATHS=("/usr/local/var/postgres" "/var/pgsql" "/Library/Server/PostgreSQL/Data")
|
||||
for possible in "${COMMON_PGDATA_PATHS[@]}"
|
||||
do
|
||||
:
|
||||
if [ -f "$possible/pg_hba.conf" ]
|
||||
then
|
||||
# echo "PGDATA: $possible"
|
||||
export PGDATA=$possible
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function postgres_start {
|
||||
about 'Starts PostgreSQL server'
|
||||
group 'postgres'
|
||||
|
||||
echo 'Starting Postgres....';
|
||||
$POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile start
|
||||
}
|
||||
|
||||
function postgres_stop {
|
||||
about 'Stops PostgreSQL server'
|
||||
group 'postgres'
|
||||
|
||||
echo 'Stopping Postgres....';
|
||||
$POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile stop -s -m fast
|
||||
}
|
||||
|
||||
function postgres_status {
|
||||
about 'Returns status of PostgreSQL server'
|
||||
group 'postgres'
|
||||
|
||||
# $POSTGRES_BIN/pg_ctl -D $PGDATA status
|
||||
if [[ $(is_postgres_running) == "no server running" ]]
|
||||
then
|
||||
echo "Postgres service [STOPPED]"
|
||||
else
|
||||
echo "Postgres service [RUNNING]"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function is_postgres_running {
|
||||
$POSTGRES_BIN/pg_ctl -D $PGDATA status | egrep -o "no server running"
|
||||
}
|
||||
|
||||
|
||||
function postgres_restart {
|
||||
about 'Restarts status of PostgreSQL server'
|
||||
group 'postgres'
|
||||
|
||||
echo 'Restarting Postgres....';
|
||||
$POSTGRES_BIN/pg_ctl -D $PGDATA restart
|
||||
}
|
||||
|
||||
function postgres_logfile {
|
||||
about 'View the last 500 lines from logfile'
|
||||
group 'postgres'
|
||||
|
||||
tail -500 $PGDATA/logfile | less
|
||||
}
|
||||
|
||||
function postgres_serverlog {
|
||||
about 'View the last 500 lines from server.log'
|
||||
group 'postgres'
|
||||
|
||||
tail -500 $PGDATA/server.log | less
|
||||
}
|
||||
|
||||
|
||||
# function postgres_syslog {
|
||||
# about 'View the last 500 lines from syslog'
|
||||
# group 'postgres'
|
||||
#
|
||||
# tail -500 $PGDATA/pg_log/`ls -Art $PGDATA/pg_log | tail -n 1` | less
|
||||
# }
|
||||
#
|
||||
26
dot_bash_it/plugins/available/powerline.plugin.bash
Normal file
26
dot_bash_it/plugins/available/powerline.plugin.bash
Normal file
@@ -0,0 +1,26 @@
|
||||
# shellcheck shell=bash
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'enables powerline daemon'
|
||||
|
||||
_command_exists powerline-daemon || return
|
||||
powerline-daemon -q
|
||||
|
||||
#the following should not be executed if bashit powerline themes in use
|
||||
case "$BASH_IT_THEME" in
|
||||
*powerline*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
POWERLINE_BASH_CONTINUATION=1
|
||||
POWERLINE_BASH_SELECT=1
|
||||
bashPowerlineInit="$(python -c \
|
||||
"import os; \
|
||||
import powerline;\
|
||||
print(os.path.join(os.path.dirname(\
|
||||
powerline.__file__),\
|
||||
'bindings', \
|
||||
'bash', \
|
||||
'powerline.sh'))")"
|
||||
[ -e $bashPowerlineInit ] || return
|
||||
source $bashPowerlineInit
|
||||
57
dot_bash_it/plugins/available/projects.plugin.bash
Normal file
57
dot_bash_it/plugins/available/projects.plugin.bash
Normal file
@@ -0,0 +1,57 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'quickly navigate configured project paths'
|
||||
|
||||
: "${BASH_IT_PROJECT_PATHS:=$HOME/Projects:$HOME/src:$HOME/work}"
|
||||
|
||||
function pj() {
|
||||
about 'navigate quickly to your various project directories'
|
||||
group 'projects'
|
||||
|
||||
local proj="${1?${FUNCNAME[0]}: project name required}"
|
||||
local cmd PS3 dest d
|
||||
local -a dests
|
||||
|
||||
if [[ "$proj" == "open" ]]; then
|
||||
shift
|
||||
proj="${1}"
|
||||
cmd="${EDITOR?}"
|
||||
fi
|
||||
|
||||
# collect possible destinations to account for directories
|
||||
# with the same name in project directories
|
||||
IFS=':' read -ra dests <<< "${BASH_IT_PROJECT_PATHS?${FUNCNAME[0]}: project working folders must be configured}"
|
||||
for d in "${!dests[@]}"; do
|
||||
if [[ ! -d "${dests[d]}/${proj}" ]]; then
|
||||
unset 'dests[d]'
|
||||
fi
|
||||
done
|
||||
|
||||
case ${#dests[@]} in
|
||||
0)
|
||||
_log_error "BASH_IT_PROJECT_PATHS must contain at least one existing location"
|
||||
return 1
|
||||
;;
|
||||
1)
|
||||
dest="${dests[*]}/${proj}"
|
||||
;;
|
||||
*)
|
||||
PS3="Multiple project directories found. Please select one: "
|
||||
dests+=("cancel")
|
||||
select d in "${dests[@]}"; do
|
||||
case $d in
|
||||
"cancel")
|
||||
return
|
||||
;;
|
||||
*)
|
||||
dest="${d}/${proj}"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
"${cmd:-cd}" "${dest}"
|
||||
}
|
||||
|
||||
alias pjo="pj open"
|
||||
369
dot_bash_it/plugins/available/proxy.plugin.bash
Normal file
369
dot_bash_it/plugins/available/proxy.plugin.bash
Normal file
@@ -0,0 +1,369 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'Proxy Tools'
|
||||
|
||||
function disable-proxy() {
|
||||
about 'Disables proxy settings for Bash, npm and SSH'
|
||||
group 'proxy'
|
||||
|
||||
unset http_proxy
|
||||
unset https_proxy
|
||||
unset HTTP_PROXY
|
||||
unset HTTPS_PROXY
|
||||
unset ALL_PROXY
|
||||
unset no_proxy
|
||||
unset NO_PROXY
|
||||
echo "Disabled proxy environment variables"
|
||||
|
||||
npm-disable-proxy
|
||||
ssh-disable-proxy
|
||||
svn-disable-proxy
|
||||
}
|
||||
|
||||
function enable-proxy() {
|
||||
about 'Enables proxy settings for Bash, npm and SSH'
|
||||
group 'proxy'
|
||||
|
||||
export http_proxy="${BASH_IT_HTTP_PROXY:-}"
|
||||
export https_proxy="${BASH_IT_HTTPS_PROXY:-}"
|
||||
export HTTP_PROXY="${http_proxy:-}"
|
||||
export HTTPS_PROXY="${https_proxy:-}"
|
||||
export ALL_PROXY="${http_proxy:-}"
|
||||
export no_proxy="${BASH_IT_NO_PROXY:-}"
|
||||
export NO_PROXY="${no_proxy:-}"
|
||||
echo "Enabled proxy environment variables"
|
||||
|
||||
npm-enable-proxy
|
||||
ssh-enable-proxy
|
||||
svn-enable-proxy
|
||||
}
|
||||
|
||||
function enable-proxy-alt() {
|
||||
about 'Enables alternate proxy settings for Bash, npm and SSH'
|
||||
group 'proxy'
|
||||
|
||||
export http_proxy="${BASH_IT_HTTP_PROXY_ALT:-}"
|
||||
export https_proxy="${BASH_IT_HTTPS_PROXY_ALT:-}"
|
||||
export HTTP_PROXY="${http_proxy:-}"
|
||||
export HTTPS_PROXY="${https_proxy:-}"
|
||||
export ALL_PROXY="${http_proxy:-}"
|
||||
export no_proxy="${BASH_IT_NO_PROXY:-}"
|
||||
export NO_PROXY="${no_proxy:-}"
|
||||
echo "Enabled alternate proxy environment variables"
|
||||
|
||||
npm-enable-proxy "${http_proxy:-}" "${https_proxy:-}"
|
||||
ssh-enable-proxy
|
||||
svn-enable-proxy "${http_proxy:-}"
|
||||
}
|
||||
|
||||
function show-proxy() {
|
||||
about 'Shows the proxy settings for Bash, Git, npm and SSH'
|
||||
group 'proxy'
|
||||
|
||||
echo ""
|
||||
echo "Environment Variables"
|
||||
echo "====================="
|
||||
env | grep -i "proxy" | grep -v "BASH_IT"
|
||||
|
||||
bash-it-show-proxy
|
||||
npm-show-proxy
|
||||
git-global-show-proxy
|
||||
svn-show-proxy
|
||||
ssh-show-proxy
|
||||
}
|
||||
|
||||
function proxy-help() {
|
||||
about 'Provides an overview of the bash-it proxy configuration'
|
||||
group 'proxy'
|
||||
|
||||
cat << EOF
|
||||
Bash-it provides support for enabling/disabling proxy settings for various shell tools.
|
||||
|
||||
The following backends are currently supported (in addition to the shell's environment variables): Git, SVN, npm, ssh
|
||||
|
||||
Bash-it uses the following variables to set the shell's proxy settings when you call 'enable-proxy'.
|
||||
These variables are best defined in a custom script in bash-it's custom script folder ('$BASH_IT/custom'),
|
||||
e.g. '$BASH_IT/custom/proxy.env.bash'
|
||||
* BASH_IT_HTTP_PROXY and BASH_IT_HTTPS_PROXY: Define the proxy URL to be used, e.g. 'http://localhost:1234'
|
||||
* BASH_IT_NO_PROXY: A comma-separated list of proxy exclusions, e.g. '127.0.0.1,localhost'
|
||||
|
||||
Run 'glossary proxy' to show the available proxy functions with a short description.
|
||||
EOF
|
||||
|
||||
bash-it-show-proxy
|
||||
}
|
||||
|
||||
function bash-it-show-proxy() {
|
||||
about 'Shows the bash-it proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
echo ""
|
||||
echo "bash-it Environment Variables"
|
||||
echo "============================="
|
||||
echo "(These variables will be used to set the proxy when you call 'enable-proxy')"
|
||||
echo ""
|
||||
env | grep -e "BASH_IT.*PROXY"
|
||||
}
|
||||
|
||||
function npm-show-proxy() {
|
||||
about 'Shows the npm proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists npm; then
|
||||
echo ""
|
||||
echo "npm"
|
||||
echo "==="
|
||||
echo "npm HTTP proxy: $(npm config get proxy)"
|
||||
echo "npm HTTPS proxy: $(npm config get https-proxy)"
|
||||
echo "npm proxy exceptions: $(npm config get noproxy)"
|
||||
fi
|
||||
}
|
||||
|
||||
function npm-disable-proxy() {
|
||||
about 'Disables npm proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists npm; then
|
||||
npm config delete proxy
|
||||
npm config delete https-proxy
|
||||
npm config delete noproxy
|
||||
echo "Disabled npm proxy settings"
|
||||
fi
|
||||
}
|
||||
|
||||
function npm-enable-proxy() {
|
||||
about 'Enables npm proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
local my_http_proxy="${1:-${BASH_IT_HTTP_PROXY:-}}"
|
||||
local my_https_proxy="${2:-${BASH_IT_HTTPS_PROXY:-}}"
|
||||
local my_no_proxy="${3:-${BASH_IT_NO_PROXY:-}}"
|
||||
|
||||
if _command_exists npm; then
|
||||
npm config set proxy "${my_http_proxy:?}" || return
|
||||
npm config set https-proxy "${my_https_proxy:?}" || return
|
||||
npm config set noproxy "${my_no_proxy:-}" || return
|
||||
echo "Enabled npm proxy settings"
|
||||
fi
|
||||
}
|
||||
|
||||
function git-global-show-proxy() {
|
||||
about 'Shows global Git proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists git; then
|
||||
echo ""
|
||||
echo "Git (Global Settings)"
|
||||
echo "====================="
|
||||
echo "Git (Global) HTTP proxy: $(git config --global --get http.proxy)"
|
||||
echo "Git (Global) HTTPS proxy: $(git config --global --get https.proxy)"
|
||||
fi
|
||||
}
|
||||
|
||||
function git-global-disable-proxy() {
|
||||
about 'Disables global Git proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists git; then
|
||||
git config --global --unset-all http.proxy
|
||||
git config --global --unset-all https.proxy
|
||||
echo "Disabled global Git proxy settings"
|
||||
fi
|
||||
}
|
||||
|
||||
function git-global-enable-proxy() {
|
||||
about 'Enables global Git proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists git; then
|
||||
git-global-disable-proxy
|
||||
|
||||
git config --global --add http.proxy "${BASH_IT_HTTP_PROXY:?}"
|
||||
git config --global --add https.proxy "${BASH_IT_HTTPS_PROXY:?}"
|
||||
echo "Enabled global Git proxy settings"
|
||||
fi
|
||||
}
|
||||
|
||||
function git-show-proxy() {
|
||||
about 'Shows current Git project proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists git; then
|
||||
echo "Git Project Proxy Settings"
|
||||
echo "====================="
|
||||
echo "Git HTTP proxy: $(git config --get http.proxy)"
|
||||
echo "Git HTTPS proxy: $(git config --get https.proxy)"
|
||||
fi
|
||||
}
|
||||
|
||||
function git-disable-proxy() {
|
||||
about 'Disables current Git project proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists git; then
|
||||
git config --unset-all http.proxy
|
||||
git config --unset-all https.proxy
|
||||
echo "Disabled Git project proxy settings"
|
||||
fi
|
||||
}
|
||||
|
||||
function git-enable-proxy() {
|
||||
about 'Enables current Git project proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists git; then
|
||||
git-disable-proxy
|
||||
|
||||
git config --add http.proxy "${BASH_IT_HTTP_PROXY:?}"
|
||||
git config --add https.proxy "${BASH_IT_HTTPS_PROXY:?}"
|
||||
echo "Enabled Git project proxy settings"
|
||||
fi
|
||||
}
|
||||
|
||||
function svn-show-proxy() {
|
||||
about 'Shows SVN proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists svn && _command_exists python2; then
|
||||
echo ""
|
||||
echo "SVN Proxy Settings"
|
||||
echo "=================="
|
||||
python2 - << END
|
||||
import ConfigParser, os
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(os.path.expanduser('~/.subversion/servers'))
|
||||
if (config.has_section('global')):
|
||||
proxy_host = ''
|
||||
proxy_port = ''
|
||||
proxy_exceptions = ''
|
||||
if (config.has_option('global', 'http-proxy-host')):
|
||||
proxy_host = config.get('global', 'http-proxy-host')
|
||||
if (config.has_option('global', 'http-proxy-port')):
|
||||
proxy_port = config.get('global', 'http-proxy-port')
|
||||
if (config.has_option('global', 'http-proxy-exceptions')):
|
||||
proxy_exceptions = config.get('global', 'http-proxy-exceptions')
|
||||
print 'http-proxy-host : ' + proxy_host
|
||||
print 'http-proxy-port : ' + proxy_port
|
||||
print 'http-proxy-exceptions: ' + proxy_exceptions
|
||||
END
|
||||
fi
|
||||
}
|
||||
|
||||
function svn-disable-proxy() {
|
||||
about 'Disables SVN proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists svn_command_exists python2; then
|
||||
python2 - << END
|
||||
import ConfigParser, os
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(os.path.expanduser('~/.subversion/servers'))
|
||||
if config.has_section('global'):
|
||||
changed = False
|
||||
if config.has_option('global', 'http-proxy-host'):
|
||||
config.remove_option('global', 'http-proxy-host')
|
||||
changed = True
|
||||
if config.has_option('global', 'http-proxy-port'):
|
||||
config.remove_option('global', 'http-proxy-port')
|
||||
changed = True
|
||||
if config.has_option('global', 'http-proxy-exceptions'):
|
||||
config.remove_option('global', 'http-proxy-exceptions')
|
||||
changed = True
|
||||
if changed:
|
||||
with open(os.path.expanduser('~/.subversion/servers'), 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
print 'Disabled SVN proxy settings'
|
||||
END
|
||||
fi
|
||||
}
|
||||
|
||||
function svn-enable-proxy() {
|
||||
about 'Enables SVN proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if _command_exists svn _command_exists python2; then
|
||||
local my_http_proxy="${1:-${BASH_IT_HTTP_PROXY:-}}"
|
||||
|
||||
python2 - "${my_http_proxy:?}" "${BASH_IT_NO_PROXY:-}" << END
|
||||
import ConfigParser, os, sys, urlparse
|
||||
pieces = urlparse.urlparse(sys.argv[1])
|
||||
host = pieces.hostname
|
||||
port = pieces.port
|
||||
exceptions = sys.argv[2]
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(os.path.expanduser('~/.subversion/servers'))
|
||||
if not config.has_section('global'):
|
||||
config.add_section('global')
|
||||
if host is not None:
|
||||
config.set('global', 'http-proxy-host', host)
|
||||
else:
|
||||
config.remove_option('global', 'http-proxy-host')
|
||||
if port is not None:
|
||||
config.set('global', 'http-proxy-port', port)
|
||||
else:
|
||||
config.remove_option('global', 'http-proxy-port')
|
||||
if exceptions is not None:
|
||||
config.set('global', 'http-proxy-exceptions', exceptions)
|
||||
else:
|
||||
config.remove_option('global', 'http-proxy-exceptions')
|
||||
with open(os.path.expanduser('~/.subversion/servers'), 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
print 'Enabled SVN proxy settings'
|
||||
END
|
||||
fi
|
||||
}
|
||||
|
||||
function ssh-show-proxy() {
|
||||
about 'Shows SSH config proxy settings (from ~/.ssh/config)'
|
||||
group 'proxy'
|
||||
|
||||
if [ -f ~/.ssh/config ]; then
|
||||
echo ""
|
||||
echo "SSH Config Enabled in ~/.ssh/config"
|
||||
echo "==================================="
|
||||
awk '
|
||||
$1 == "Host" {
|
||||
host = $2;
|
||||
next;
|
||||
}
|
||||
$1 == "ProxyCommand" {
|
||||
$1 = "";
|
||||
printf "%s\t%s\n", host, $0
|
||||
}
|
||||
' ~/.ssh/config | column -t
|
||||
|
||||
echo ""
|
||||
echo "SSH Config Disabled in ~/.ssh/config"
|
||||
echo "===================================="
|
||||
awk '
|
||||
$1 == "Host" {
|
||||
host = $2;
|
||||
next;
|
||||
}
|
||||
$0 ~ "^#.*ProxyCommand.*" {
|
||||
$1 = "";
|
||||
$2 = "";
|
||||
printf "%s\t%s\n", host, $0
|
||||
}
|
||||
' ~/.ssh/config | column -t
|
||||
fi
|
||||
}
|
||||
|
||||
function ssh-disable-proxy() {
|
||||
about 'Disables SSH config proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if [ -f ~/.ssh/config ]; then
|
||||
sed -e's/^.*ProxyCommand/# ProxyCommand/' "${BASH_IT_SED_I_PARAMETERS[@]}" ~/.ssh/config
|
||||
echo "Disabled SSH config proxy settings"
|
||||
fi
|
||||
}
|
||||
|
||||
function ssh-enable-proxy() {
|
||||
about 'Enables SSH config proxy settings'
|
||||
group 'proxy'
|
||||
|
||||
if [ -f ~/.ssh/config ]; then
|
||||
sed -e's/# ProxyCommand/ ProxyCommand/' "${BASH_IT_SED_I_PARAMETERS[@]}" ~/.ssh/config
|
||||
echo "Enabled SSH config proxy settings"
|
||||
fi
|
||||
}
|
||||
34
dot_bash_it/plugins/available/pyenv.plugin.bash
Normal file
34
dot_bash_it/plugins/available/pyenv.plugin.bash
Normal file
@@ -0,0 +1,34 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load pyenv, if you are using it'
|
||||
|
||||
# https://github.com/pyenv/pyenv
|
||||
|
||||
# Load after basher
|
||||
# BASH_IT_LOAD_PRIORITY: 260
|
||||
|
||||
# Don't modify the environment if we can't find the tool:
|
||||
# - Check if in $PATH already
|
||||
# - Check if installed manually to $PYENV_ROOT
|
||||
# - Check if installed manually to $HOME
|
||||
_command_exists pyenv \
|
||||
|| [[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] \
|
||||
|| [[ -x "$HOME/.pyenv/bin/pyenv" ]] \
|
||||
|| return 0
|
||||
|
||||
# Set PYENV_ROOT, if not already set
|
||||
export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"
|
||||
|
||||
# Add PYENV_ROOT/bin to PATH, if that's where it's installed
|
||||
if ! _command_exists pyenv && [[ -x "$PYENV_ROOT/bin/pyenv" ]]; then
|
||||
pathmunge "$PYENV_ROOT/bin"
|
||||
fi
|
||||
|
||||
# Initialize pyenv
|
||||
pathmunge "$PYENV_ROOT/shims"
|
||||
eval "$(pyenv init - bash)"
|
||||
|
||||
# Load pyenv virtualenv if the virtualenv plugin is installed.
|
||||
if pyenv virtualenv-init - &> /dev/null; then
|
||||
eval "$(pyenv virtualenv-init - bash)"
|
||||
fi
|
||||
32
dot_bash_it/plugins/available/python.plugin.bash
Normal file
32
dot_bash_it/plugins/available/python.plugin.bash
Normal file
@@ -0,0 +1,32 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'alias "shttp" to SimpleHTTPServer'
|
||||
|
||||
if _command_exists python3; then
|
||||
alias shttp='python3 -m http.server'
|
||||
elif _command_exists python; then
|
||||
alias shttp='python -m http.server'
|
||||
else
|
||||
_log_warning "Unable to load 'plugin/python' due to being unable to find a working 'python'"
|
||||
return 1
|
||||
fi
|
||||
|
||||
function pyedit() {
|
||||
about 'opens python module in your EDITOR'
|
||||
param '1: python module to open'
|
||||
example '$ pyedit requests'
|
||||
group 'python'
|
||||
|
||||
xpyc="$(python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)")"
|
||||
|
||||
if [[ "$xpyc" == "" ]]; then
|
||||
echo "Python module $1 not found"
|
||||
return 1
|
||||
elif [[ "$xpyc" == *__init__.py* ]]; then
|
||||
xpydir="${xpyc%/*}"
|
||||
echo "$EDITOR $xpydir"
|
||||
${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}} "$xpydir"
|
||||
else
|
||||
echo "$EDITOR ${xpyc%.*}.py"
|
||||
${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}} "${xpyc%.*}.py"
|
||||
fi
|
||||
}
|
||||
18
dot_bash_it/plugins/available/rails.plugin.bash
Normal file
18
dot_bash_it/plugins/available/rails.plugin.bash
Normal file
@@ -0,0 +1,18 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Helper functions for Ruby on Rails'
|
||||
|
||||
# Quick function to kill a daemonized Rails server
|
||||
function killrails() {
|
||||
about 'Searches for a daemonized Rails server in tmp/pids and attempts to kill it.'
|
||||
group 'rails'
|
||||
|
||||
railsPid="$(cat tmp/pids/server.pid)"
|
||||
if [ ! -z "$railsPid" ]; then
|
||||
echo "[OK] Rails Server Process Id : ${railsPid}"
|
||||
kill -9 $railsPid
|
||||
echo "[OK] Process Killed"
|
||||
else
|
||||
echo "[FAIL] Error killing Rails server"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
10
dot_bash_it/plugins/available/rbenv.plugin.bash
Normal file
10
dot_bash_it/plugins/available/rbenv.plugin.bash
Normal file
@@ -0,0 +1,10 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load rbenv, if you are using it'
|
||||
|
||||
export RBENV_ROOT="$HOME/.rbenv"
|
||||
pathmunge "$RBENV_ROOT/bin"
|
||||
|
||||
if _command_exists rbenv; then
|
||||
eval "$(rbenv init - bash)"
|
||||
fi
|
||||
17
dot_bash_it/plugins/available/ruby.plugin.bash
Normal file
17
dot_bash_it/plugins/available/ruby.plugin.bash
Normal file
@@ -0,0 +1,17 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'ruby and rubygems specific functions and settings'
|
||||
|
||||
# Make commands installed with 'gem install --user-install' available
|
||||
# ~/.gem/ruby/${RUBY_VERSION}/bin/
|
||||
if _command_exists ruby && _command_exists gem; then
|
||||
pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after
|
||||
fi
|
||||
|
||||
function remove_gem() {
|
||||
about 'removes installed gem'
|
||||
param '1: installed gem name'
|
||||
group 'ruby'
|
||||
|
||||
gem list | grep "${1:?${FUNCNAME[0]}: no gem name provided}" | awk '{ print $1; }' | xargs sudo gem uninstall
|
||||
}
|
||||
31
dot_bash_it/plugins/available/rvm.plugin.bash
Normal file
31
dot_bash_it/plugins/available/rvm.plugin.bash
Normal file
@@ -0,0 +1,31 @@
|
||||
# Load RVM, if you are using it
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'load rvm, if you are using it'
|
||||
|
||||
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
|
||||
|
||||
# Check to make sure that RVM is actually loaded before adding
|
||||
# the customizations to it.
|
||||
if [ "$rvm_path" ]
|
||||
then
|
||||
# Load the auto-completion script if RVM was loaded.
|
||||
[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion
|
||||
|
||||
switch () {
|
||||
rvm $1
|
||||
local v=$(rvm_version)
|
||||
rvm wrapper $1 textmate
|
||||
echo "Switch to Ruby version: "$v
|
||||
}
|
||||
|
||||
rvm_default () {
|
||||
rvm --default $1
|
||||
rvm wrapper $1 textmate
|
||||
}
|
||||
|
||||
function rvm_version () {
|
||||
ruby --version
|
||||
}
|
||||
|
||||
fi
|
||||
8
dot_bash_it/plugins/available/sdkman.plugin.bash
Normal file
8
dot_bash_it/plugins/available/sdkman.plugin.bash
Normal file
@@ -0,0 +1,8 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Load Software Development Kit Manager'
|
||||
|
||||
# Use $SDKMAN_DIR if defined,
|
||||
# otherwise default to ~/.sdkman
|
||||
export SDKMAN_DIR=${SDKMAN_DIR:-$HOME/.sdkman}
|
||||
|
||||
[[ -s "${SDKMAN_DIR}/bin/sdkman-init.sh" ]] && source "${SDKMAN_DIR}/bin/sdkman-init.sh"
|
||||
29
dot_bash_it/plugins/available/ssh.plugin.bash
Normal file
29
dot_bash_it/plugins/available/ssh.plugin.bash
Normal file
@@ -0,0 +1,29 @@
|
||||
cite about-plugin
|
||||
about-plugin 'ssh helper functions'
|
||||
|
||||
function add_ssh() {
|
||||
about 'add entry to ssh config'
|
||||
param '1: host'
|
||||
param '2: hostname'
|
||||
param '3: user'
|
||||
group 'ssh'
|
||||
|
||||
[[ $# -ne 3 ]] && echo "add_ssh host hostname user" && return 1
|
||||
[[ ! -d ~/.ssh ]] && mkdir -m 700 ~/.ssh
|
||||
[[ ! -e ~/.ssh/config ]] && touch ~/.ssh/config && chmod 600 ~/.ssh/config
|
||||
echo -en "\n\nHost $1\n HostName $2\n User $3\n ServerAliveInterval 30\n ServerAliveCountMax 120" >> ~/.ssh/config
|
||||
}
|
||||
|
||||
function sshlist() {
|
||||
about 'list hosts defined in ssh config'
|
||||
group 'ssh'
|
||||
|
||||
awk '$1 ~ /Host$/ {for (i=2; i<=NF; i++) print $i}' ~/.ssh/config
|
||||
}
|
||||
|
||||
function ssh-add-all() {
|
||||
about 'add all ssh private keys to agent'
|
||||
group 'ssh'
|
||||
|
||||
grep -slR "PRIVATE" ~/.ssh | xargs ssh-add
|
||||
}
|
||||
143
dot_bash_it/plugins/available/sshagent.plugin.bash
Normal file
143
dot_bash_it/plugins/available/sshagent.plugin.bash
Normal file
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env bash
|
||||
cite about-plugin
|
||||
about-plugin 'sshagent helper functions'
|
||||
|
||||
function _get_sshagent_pid_from_env_file() {
|
||||
local env_file="${1}"
|
||||
[[ -r "${env_file}" ]] || {
|
||||
echo "";
|
||||
return
|
||||
}
|
||||
tail -1 "${env_file}" \
|
||||
| cut -d' ' -f4 \
|
||||
| cut -d';' -f1
|
||||
}
|
||||
|
||||
function _get_process_status_field() {
|
||||
# uses /proc filesystem
|
||||
local \
|
||||
pid \
|
||||
status_file \
|
||||
field
|
||||
pid="${1}"
|
||||
field="${2}"
|
||||
status_file="/proc/${pid}/status"
|
||||
if ! ([[ -d "${status_file%/*}" ]] \
|
||||
&& [[ -r "${status_file}" ]]); then
|
||||
echo ""; return;
|
||||
fi
|
||||
grep "${field}:" "${status_file}" \
|
||||
| cut -d':' -f2 \
|
||||
| sed -e 's/[[:space:]]\+//g' \
|
||||
| cut -d'(' -f1
|
||||
}
|
||||
|
||||
function _is_item_in_list() {
|
||||
local item
|
||||
for item in "${@:1}"; do
|
||||
if [[ "${item}" == "${1}" ]]; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
function _is_proc_alive_at_pid() {
|
||||
local \
|
||||
pid \
|
||||
expected_name \
|
||||
actual_name \
|
||||
actual_state
|
||||
pid="${1?}"
|
||||
expected_name="ssh-agent"
|
||||
# we want to exclude: X (killed), T (traced), Z (zombie)
|
||||
actual_name=$(_get_process_status_field "${pid}" "Name")
|
||||
[[ "${expected_name}" == "${actual_name}" ]] || return 1
|
||||
actual_state=$(_get_process_status_field "${pid}" "State")
|
||||
if _is_item_in_list "${actual_state}" "X" "T" "Z"; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
function _ensure_valid_sshagent_env() {
|
||||
local \
|
||||
agent_pid \
|
||||
tmp_res
|
||||
|
||||
mkdir -p "${HOME}/.ssh"
|
||||
type restorecon &> /dev/null
|
||||
tmp_res="$?"
|
||||
|
||||
if [[ "${tmp_res}" -eq 0 ]]; then
|
||||
restorecon -rv "${HOME}/.ssh"
|
||||
fi
|
||||
|
||||
# no env file -> shoot a new agent
|
||||
if ! [[ -r "${SSH_AGENT_ENV}" ]]; then
|
||||
ssh-agent > "${SSH_AGENT_ENV}"
|
||||
return
|
||||
fi
|
||||
|
||||
## do not trust pre-existing SSH_AGENT_ENV
|
||||
agent_pid=$(_get_sshagent_pid_from_env_file "${SSH_AGENT_ENV}")
|
||||
if [[ -z "${agent_pid}" ]]; then
|
||||
# no pid detected -> shoot a new agent
|
||||
ssh-agent > "${SSH_AGENT_ENV}"
|
||||
return
|
||||
fi
|
||||
|
||||
## do not trust SSH_AGENT_PID
|
||||
if _is_proc_alive_at_pid "${agent_pid}"; then
|
||||
return
|
||||
fi
|
||||
|
||||
ssh-agent > "${SSH_AGENT_ENV}"
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
function _ensure_sshagent_dead() {
|
||||
[[ -r "${SSH_AGENT_ENV}" ]] \
|
||||
|| return ## no agent file - no problems
|
||||
## ensure the file indeed points to a really running agent:
|
||||
agent_pid=$(
|
||||
_get_sshagent_pid_from_env_file \
|
||||
"${SSH_AGENT_ENV}"
|
||||
)
|
||||
|
||||
[[ -n "${agent_pid}" ]] \
|
||||
|| return # no pid - no problem
|
||||
|
||||
_is_proc_alive_at_pid "${agent_pid}" \
|
||||
|| return # process is not alive - no problem
|
||||
|
||||
echo -e -n "Killing ssh-agent (pid:${agent_pid}) ... "
|
||||
kill -9 "${agent_pid}" && echo "DONE" || echo "FAILED"
|
||||
rm -f "${SSH_AGENT_ENV}"
|
||||
}
|
||||
|
||||
|
||||
function sshagent() {
|
||||
about 'ensures ssh-agent is up and running'
|
||||
param '1: on|off '
|
||||
example '$ sshagent on'
|
||||
group 'ssh'
|
||||
[[ -z "${SSH_AGENT_ENV}" ]] \
|
||||
&& export SSH_AGENT_ENV="${HOME}/.ssh/agent_env.${HOSTNAME}"
|
||||
|
||||
case "${1}" in
|
||||
on) _ensure_valid_sshagent_env;
|
||||
# shellcheck disable=SC1090
|
||||
source "${SSH_AGENT_ENV}" > /dev/null;
|
||||
;;
|
||||
off) _ensure_sshagent_dead
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
sshagent on
|
||||
21
dot_bash_it/plugins/available/subversion.plugin.bash
Normal file
21
dot_bash_it/plugins/available/subversion.plugin.bash
Normal file
@@ -0,0 +1,21 @@
|
||||
cite about-plugin
|
||||
about-plugin 'svn helper functions'
|
||||
|
||||
rm_svn(){
|
||||
about 'remove ".svn" files from directory'
|
||||
param '1: directory to search for files'
|
||||
group 'svn'
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
reference rm_svn
|
||||
return
|
||||
fi
|
||||
find $1 -name .svn -print0 | xargs -0 rm -rf
|
||||
}
|
||||
|
||||
svn_add(){
|
||||
about 'add to svn repo'
|
||||
group 'svn'
|
||||
|
||||
svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add
|
||||
}
|
||||
22
dot_bash_it/plugins/available/sudo.plugin.bash
Normal file
22
dot_bash_it/plugins/available/sudo.plugin.bash
Normal file
@@ -0,0 +1,22 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice'
|
||||
|
||||
function sudo-command-line() {
|
||||
about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice"
|
||||
group "sudo"
|
||||
|
||||
[[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs)
|
||||
if [[ $READLINE_LINE == sudo\ * ]]; then
|
||||
READLINE_LINE="${READLINE_LINE#sudo }"
|
||||
else
|
||||
READLINE_LINE="sudo $READLINE_LINE"
|
||||
fi
|
||||
READLINE_POINT=${#READLINE_LINE}
|
||||
}
|
||||
|
||||
# Define shortcut keys: [Esc] [Esc]
|
||||
|
||||
# Readline library requires bash version 4 or later
|
||||
if [ "${BASH_VERSINFO}" -ge 4 ]; then
|
||||
bind -x '"\e\e": sudo-command-line'
|
||||
fi
|
||||
9
dot_bash_it/plugins/available/textmate.plugin.bash
Normal file
9
dot_bash_it/plugins/available/textmate.plugin.bash
Normal file
@@ -0,0 +1,9 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'set textmate as a default editor'
|
||||
|
||||
if _command_exists mate; then
|
||||
EDITOR="$(type -p mate) -w"
|
||||
GIT_EDITOR="$EDITOR"
|
||||
export EDITOR GIT_EDITOR
|
||||
fi
|
||||
9
dot_bash_it/plugins/available/thefuck.plugin.bash
Normal file
9
dot_bash_it/plugins/available/thefuck.plugin.bash
Normal file
@@ -0,0 +1,9 @@
|
||||
cite about-plugin
|
||||
about-plugin 'Initialization for fuck'
|
||||
|
||||
# https://github.com/nvbn/thefuck
|
||||
|
||||
if _command_exists thefuck; then
|
||||
# shellcheck disable=SC2046
|
||||
eval $(thefuck --alias)
|
||||
fi
|
||||
6
dot_bash_it/plugins/available/tmux.plugin.bash
Normal file
6
dot_bash_it/plugins/available/tmux.plugin.bash
Normal file
@@ -0,0 +1,6 @@
|
||||
# make sure that tmux is launched in 256 color mode
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'make sure that tmux is launched in 256 color mode'
|
||||
|
||||
alias tmux="TERM=xterm-256color tmux"
|
||||
4
dot_bash_it/plugins/available/tmuxinator.plugin.bash
Normal file
4
dot_bash_it/plugins/available/tmuxinator.plugin.bash
Normal file
@@ -0,0 +1,4 @@
|
||||
cite about-plugin
|
||||
about-plugin 'sources tmuxinator script if available'
|
||||
|
||||
[[ -s "$HOME/.tmuxinator/scripts/tmuxinator" ]] && . "$HOME/.tmuxinator/scripts/tmuxinator"
|
||||
6
dot_bash_it/plugins/available/todo.plugin.bash
Normal file
6
dot_bash_it/plugins/available/todo.plugin.bash
Normal file
@@ -0,0 +1,6 @@
|
||||
# shellcheck shell=bash
|
||||
about-plugin 'Todo.txt integration'
|
||||
|
||||
# you may override any of the exported variables below in your .bash_profile
|
||||
: "${TODOTXT_DEFAULT_ACTION:=ls}"
|
||||
export TODOTXT_DEFAULT_ACTION
|
||||
45
dot_bash_it/plugins/available/virtualenv.plugin.bash
Normal file
45
dot_bash_it/plugins/available/virtualenv.plugin.bash
Normal file
@@ -0,0 +1,45 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# make sure virtualenvwrapper is enabled if available
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'virtualenvwrapper and pyenv-virtualenvwrapper helper functions'
|
||||
|
||||
if _command_exists pyenv; then
|
||||
pyenv virtualenvwrapper
|
||||
elif _command_exists virtualenvwrapper.sh; then
|
||||
source virtualenvwrapper.sh
|
||||
fi
|
||||
|
||||
|
||||
function mkvenv {
|
||||
about 'create a new virtualenv for this directory'
|
||||
group 'virtualenv'
|
||||
|
||||
local cwd="${PWD##*/}"
|
||||
mkvirtualenv --distribute "$cwd"
|
||||
}
|
||||
|
||||
|
||||
function mkvbranch {
|
||||
about 'create a new virtualenv for the current branch'
|
||||
group 'virtualenv'
|
||||
|
||||
local cwd="${PWD##*/}"
|
||||
mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}"
|
||||
}
|
||||
|
||||
function wovbranch {
|
||||
about 'sets workon branch'
|
||||
group 'virtualenv'
|
||||
|
||||
local cwd="${PWD##*/}"
|
||||
workon "${cwd}@${SCM_BRANCH}"
|
||||
}
|
||||
|
||||
function wovenv {
|
||||
about 'works on the virtualenv for this directory'
|
||||
group 'virtualenv'
|
||||
|
||||
workon "${PWD##*/}"
|
||||
}
|
||||
45
dot_bash_it/plugins/available/xterm.plugin.bash
Normal file
45
dot_bash_it/plugins/available/xterm.plugin.bash
Normal file
@@ -0,0 +1,45 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'automatically set your xterm title with host and location info'
|
||||
|
||||
_short-dirname() {
|
||||
local dir_name="${PWD/~/\~}"
|
||||
if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then
|
||||
echo "${dir_name##*/}"
|
||||
else
|
||||
echo "${dir_name}"
|
||||
fi
|
||||
}
|
||||
|
||||
_short-command() {
|
||||
local input_command="$*"
|
||||
if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then
|
||||
echo "${input_command%% *}"
|
||||
else
|
||||
echo "${input_command}"
|
||||
fi
|
||||
}
|
||||
|
||||
set_xterm_title() {
|
||||
local title="${1:-}"
|
||||
echo -ne "\033]0;${title}\007"
|
||||
}
|
||||
|
||||
precmd_xterm_title() {
|
||||
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}"
|
||||
}
|
||||
|
||||
preexec_xterm_title() {
|
||||
local command_line="${BASH_COMMAND:-${1:-}}"
|
||||
local directory_name short_command
|
||||
directory_name="$(_short-dirname)"
|
||||
short_command="$(_short-command "${command_line}")"
|
||||
set_xterm_title "${short_command} {${directory_name}} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||
}
|
||||
|
||||
case "${TERM:-dumb}" in
|
||||
xterm* | rxvt*)
|
||||
precmd_functions+=(precmd_xterm_title)
|
||||
preexec_functions+=(preexec_xterm_title)
|
||||
;;
|
||||
esac
|
||||
45
dot_bash_it/plugins/available/z_autoenv.plugin.bash
Normal file
45
dot_bash_it/plugins/available/z_autoenv.plugin.bash
Normal file
@@ -0,0 +1,45 @@
|
||||
cite about-plugin
|
||||
about-plugin 'source into environment when cding to directories'
|
||||
|
||||
if [[ -n "${ZSH_VERSION}" ]]
|
||||
then __array_offset=0
|
||||
else __array_offset=1
|
||||
fi
|
||||
|
||||
autoenv_init()
|
||||
{
|
||||
typeset target home _file
|
||||
typeset -a _files
|
||||
target=$1
|
||||
home="${HOME%/*}"
|
||||
|
||||
_files=( $(
|
||||
while [[ "$PWD" != "/" && "$PWD" != "$home" ]]
|
||||
do
|
||||
_file="$PWD/.env"
|
||||
if [[ -e "${_file}" ]]
|
||||
then echo "${_file}"
|
||||
fi
|
||||
builtin cd ..
|
||||
done
|
||||
) )
|
||||
|
||||
_file=${#_files[@]}
|
||||
while (( _file > 0 ))
|
||||
do
|
||||
source "${_files[_file-__array_offset]}"
|
||||
: $(( _file -= 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
cd()
|
||||
{
|
||||
if builtin cd "$@"
|
||||
then
|
||||
autoenv_init
|
||||
return 0
|
||||
else
|
||||
echo "else?"
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
9
dot_bash_it/plugins/available/zoxide.plugin.bash
Normal file
9
dot_bash_it/plugins/available/zoxide.plugin.bash
Normal file
@@ -0,0 +1,9 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'zoxide is a smarter cd command for your shell.'
|
||||
|
||||
if _command_exists zoxide; then
|
||||
eval "$(zoxide init bash)"
|
||||
else
|
||||
_log_error 'zoxide not found, please install it from https://github.com/ajeetdsouza/zoxide'
|
||||
fi
|
||||
Reference in New Issue
Block a user