Improve oh-my-bash functionality

* Implement aliases, completion in oh-my-bash
 * Added default themes from Bash-it
 * Fixed few issues
This commit is contained in:
Toan Nguyen 2017-10-10 18:07:01 +07:00
parent f0510e0e16
commit e65c390bfa
138 changed files with 18119 additions and 233 deletions

5
.gitignore vendored

@ -1,7 +1,10 @@
# custom files
/custom/
!/custom/aliases/example.aliases.sh
!/custom/completion/example.completion.sh
!/custom/plugins/example/
!/custom/themes/example/
!/custom/example.sh
/custom/
# temp files directories
/cache/

155
aliases/general.aliases.sh Normal file

@ -0,0 +1,155 @@
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
#
# Description: This file holds all general BASH aliases
#
# Sections:
# 1. Make Terminal Better (remapping defaults and adding functionality)
# 2. File and Folder Management
# 3. Searching
# 4. Process Management
# 5. Networking
# 6. System Operations & Information
# 7. Date & Time Management
# 8. Web Development
# 9. <your_section>
#
# X. Reminders & Notes
#
# ---------------------------------------------------------------------------
# -----------------------------
# 1. MAKE TERMINAL BETTER
# -----------------------------
alias cp='cp -iv' # Preferred 'cp' implementation
alias mv='mv -iv' # Preferred 'mv' implementation
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation
alias ll='ls -lAFh' # Preferred 'ls' implementation
alias less='less -FSRXc' # Preferred 'less' implementation
alias nano='nano -W -$' # Preferred 'nano' implementation
alias wget='wget -c' # Preferred 'wget' implementation (resume download)
alias cd..='cd ../' # Go back 1 directory level (for fast typers)
alias ..='cd ../' # Go back 1 directory level
alias ...='cd ../../' # Go back 2 directory levels
alias .3='cd ../../../' # Go back 3 directory levels
alias .4='cd ../../../../' # Go back 4 directory levels
alias .5='cd ../../../../../' # Go back 5 directory levels
alias .6='cd ../../../../../../' # Go back 6 directory levels
alias dud='du -d 1 -h' # Short and human-readable file listing
alias duf='du -sh *' # Short and human-readable directory listing
alias ~="cd ~" # ~: Go Home
alias c='clear' # c: Clear terminal display
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths
alias show_options='shopt' # Show_options: display bash options settings
alias fix_stty='stty sane' # fix_stty: Restore terminal settings when screwed up
alias cic='set completion-ignore-case On' # cic: Make tab-completion case-insensitive
alias h='fc -l 1 | grep $1' # h: Find an executed command in .bash_history
alias src='source ~/.bashrc' # src: Reload .bashrc file
# lr: Full Recursive Directory Listing
# ------------------------------------------
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less'
# -------------------------------
# 2. FILE AND FOLDER MANAGEMENT
# -------------------------------
alias numFiles='echo $(ls -1 | wc -l)' # numFiles: Count of non-hidden files in current dir
alias make1mb='truncate -s 1m ./1MB.dat' # make1mb: Creates a file of 1mb size (all zeros)
alias make5mb='truncate -s 5m ./5MB.dat' # make5mb: Creates a file of 5mb size (all zeros)
alias make10mb='truncate -s 10m ./10MB.dat' # make10mb: Creates a file of 10mb size (all zeros)
# ---------------------------
# 3. SEARCHING
# ---------------------------
alias qfind="find . -name " # qfind: Quickly search for file
# ---------------------------
# 4. PROCESS MANAGEMENT
# ---------------------------
# memHogsTop, memHogsPs: Find memory hogs
# -----------------------------------------------------
alias memHogsTop='top -l 1 -o rsize | head -20'
alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'
# cpuHogs: Find CPU hogs
# -----------------------------------------------------
alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'
# topForever: Continual 'top' listing (every 10 seconds)
# -----------------------------------------------------
alias topForever='top -l 9999999 -s 10 -o cpu'
# ttop: Recommended 'top' invocation to minimize resources
# ------------------------------------------------------------
# Taken from this macosxhints article
# http://www.macosxhints.com/article.php?story=20060816123853639
# ------------------------------------------------------------
alias ttop="top -R -F -s 10 -o rsize"
# ---------------------------
# 5. NETWORKING
# ---------------------------
alias netCons='lsof -i' # netCons: Show all open TCP/IP sockets
alias lsock='sudo /usr/sbin/lsof -i -P' # lsock: Display open sockets
alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP' # lsockU: Display only open UDP sockets
alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP' # lsockT: Display only open TCP sockets
alias ipInfo0='ifconfig getpacket en0' # ipInfo0: Get info on connections for en0
alias ipInfo1='ifconfig getpacket en1' # ipInfo1: Get info on connections for en1
alias openPorts='sudo lsof -i | grep LISTEN' # openPorts: All listening connections
alias showBlocked='sudo ipfw list' # showBlocked: All ipfw rules inc/ blocked IPs
# ---------------------------------------
# 6. SYSTEMS OPERATIONS & INFORMATION
# ---------------------------------------
alias mountReadWrite='/sbin/mount -uw /' # mountReadWrite: For use when booted into single-user
alias perm='stat --printf "%a %n \n "' # perm: Show permission of target in number
alias 000='chmod 000' # ---------- (no fucking permissions)
alias 640='chmod 640' # -rw-r----- (user: rw, group: r, other: -)
alias 644='chmod 644' # -rw-r--r-- (user: rw, group: r, other: -)
alias 755='chmod 755' # -rwxr-xr-x (user: rwx, group: rx, other: x)
alias 775='chmod 775' # -rwxrwxr-x (user: rwx, group: rwx, other: rx)
alias mx='chmod a+x' # ---x--x--x (user: --x, group: --x, other: --x)
alias ux='chmod u+x' # ---x------ (user: --x, group: -, other: -)
# ---------------------------------------
# 7. DATE & TIME MANAGEMENT
# ---------------------------------------
alias bdate="date '+%a, %b %d %Y %T %Z'"
alias cal='cal -3'
alias da='date "+%Y-%m-%d %A %T %Z"'
alias daysleft='echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)."'
alias epochtime='date +%s'
alias mytime='date +%H:%M:%S'
alias secconvert='date -d@1234567890'
alias stamp='date "+%Y%m%d%a%H%M"'
alias timestamp='date "+%Y%m%dT%H%M%S"'
alias today='date +"%A, %B %-d, %Y"'
alias weeknum='date +%V'
# ---------------------------------------
# 8. WEB DEVELOPMENT
# ---------------------------------------
alias apacheEdit='sudo edit /etc/httpd/httpd.conf' # apacheEdit: Edit httpd.conf
alias apacheRestart='sudo apachectl graceful' # apacheRestart: Restart Apache
alias editHosts='sudo edit /etc/hosts' # editHosts: Edit /etc/hosts file
alias herr='tail /var/log/httpd/error_log' # herr: Tails HTTP error logs
alias apacheLogs="less +F /var/log/apache2/error_log" # Apachelogs: Shows apache error logs
# ---------------------------------------
# 9. REMINDERS & NOTES
# ---------------------------------------

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# apm-bash-completion is written by Ugur Ozyilmazel
# repo: https://github.com/vigo/apm-bash-completion
__apm(){
local cur prev options apm_command
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
__apm_get_command
if [[ $cur = -* ]]; then
options="--color"
if [[ -z $apm_command ]]; then
options="$options --version --help"
fi
if [[ $apm_command && $apm_command = publish ]]; then
options="--tag --rename"
fi
else
if [[ -z $apm_command || $apm_command = help ]]; then
options="help clean config dedupe deinstall delete dev develop docs erase featured home init install link linked links list ln lns login ls open outdated publish rebuild rebuild-module-cache remove rm search show star starred stars test uninstall unlink unpublish unstar update upgrade view"
fi
if [[ $apm_command && $apm_command = publish ]]; then
options="major minor patch build"
fi
if [[ $apm_command && $apm_command = config ]]; then
options="set get delete list edit"
fi
fi
COMPREPLY=($(compgen -W "$options" -- "$cur"))
}
__apm_get_command() {
local i
for ((i=1; i < $COMP_CWORD; ++i)); do
local arg=${COMP_WORDS[$i]}
case $arg in
[^-]*)
apm_command=$arg
return;;
--version)
apm_command=-
return;;
--help)
apm_command=help
return;;
publish)
apm_command=publish
return;;
config)
apm_command=config
return;;
esac
done
}
complete -F __apm -o bashdefault -o default apm

@ -0,0 +1 @@
[[ -x "$(which aws_completer)" ]] && complete -C "$(which aws_completer)" aws

@ -0,0 +1,9 @@
if which brew >/dev/null 2>&1; then
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
if [ -f `brew --prefix`/Library/Contributions/brew_bash_completion.sh ]; then
. `brew --prefix`/Library/Contributions/brew_bash_completion.sh
fi
fi

@ -0,0 +1,55 @@
#! bash
# bash completion for the `bundle` command.
#
# Copyright (c) 2011-2013 Daniel Luz <dev at mernen dot com>.
# Distributed under the MIT license.
# http://mernen.com/projects/completion-ruby
#
# To use, source this file on bash:
# . completion-bundle
__bundle() {
local cur=$2
local prev=$3
local bundle_command
__bundle_get_command
COMPREPLY=()
local options
if [[ $cur = -* ]]; then
options="--no-color --verbose"
if [[ -z $bundle_command ]]; then
options="$options --version --help"
fi
else
if [[ -z $bundle_command || $bundle_command = help ]]; then
options="help install update package exec config check list show
console open viz init gem"
fi
fi
COMPREPLY=($(compgen -W "$options" -- "$cur"))
}
__bundle_get_command() {
local i
for ((i=1; i < $COMP_CWORD; ++i)); do
local arg=${COMP_WORDS[$i]}
case $arg in
[^-]*)
bundle_command=$arg
return;;
--version)
# command-killer
bundle_command=-
return;;
--help)
bundle_command=help
return;;
esac
done
}
complete -F __bundle -o bashdefault -o default bundle
# vim: ai ft=sh sw=4 sts=2 et

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Bash completion support for Capistrano.
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
_capcomplete() {
if [ -f Capfile ]; then
recent=`ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1`
if [[ $recent != '.cap_tasks~' ]]; then
cap --version | grep 'Capistrano v2.' > /dev/null
if [ $? -eq 0 ]; then
# Capistrano 2.x
cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~
else
# Capistrano 3.x
cap --all --tasks | cut -d " " -f 2 > .cap_tasks~
fi
fi
COMPREPLY=($(compgen -W "`cat .cap_tasks~`" -- ${COMP_WORDS[COMP_CWORD]}))
return 0
fi
}
complete -o default -o nospace -F _capcomplete cap

@ -0,0 +1,133 @@
#!/usr/bin/env bash
_composer()
{
local cur script coms opts com
COMPREPLY=()
_get_comp_words_by_ref -n : cur words
# for an alias, get the real script behind it
if [[ $(type -t ${words[0]}) == "alias" ]]; then
script=$(alias ${words[0]} | sed -E "s/alias ${words[0]}='(.*)'/\1/")
else
script=${words[0]}
fi
# lookup for command
for word in ${words[@]:1}; do
if [[ $word != -* ]]; then
com=$word
break
fi
done
# completing for an option
if [[ ${cur} == --* ]] ; then
opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir"
case "$com" in
about)
opts="${opts} "
;;
archive)
opts="${opts} --format --dir --file"
;;
browse)
opts="${opts} --homepage --show"
;;
clear-cache)
opts="${opts} "
;;
config)
opts="${opts} --global --editor --auth --unset --list --file --absolute"
;;
create-project)
opts="${opts} --stability --prefer-source --prefer-dist --repository --repository-url --dev --no-dev --no-custom-installers --no-scripts --no-progress --no-secure-http --keep-vcs --no-install --ignore-platform-reqs"
;;
depends)
opts="${opts} --recursive --tree"
;;
diagnose)
opts="${opts} "
;;
dump-autoload)
opts="${opts} --no-scripts --optimize --classmap-authoritative --apcu --no-dev"
;;
exec)
opts="${opts} --list"
;;
global)
opts="${opts} "
;;
help)
opts="${opts} --xml --format --raw"
;;
init)
opts="${opts} --name --description --author --type --homepage --require --require-dev --stability --license --repository"
;;
install)
opts="${opts} --prefer-source --prefer-dist --dry-run --dev --no-dev --no-custom-installers --no-autoloader --no-scripts --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --apcu-autoloader --ignore-platform-reqs"
;;
licenses)
opts="${opts} --format --no-dev"
;;
list)
opts="${opts} --xml --raw --format"
;;
outdated)
opts="${opts} --outdated --all --direct --strict"
;;
prohibits)
opts="${opts} --recursive --tree"
;;
remove)
opts="${opts} --dev --no-progress --no-update --no-scripts --update-no-dev --update-with-dependencies --no-update-with-dependencies --ignore-platform-reqs --optimize-autoloader --classmap-authoritative --apcu-autoloader"
;;
require)
opts="${opts} --dev --prefer-source --prefer-dist --no-progress --no-suggest --no-update --no-scripts --update-no-dev --update-with-dependencies --ignore-platform-reqs --prefer-stable --prefer-lowest --sort-packages --optimize-autoloader --classmap-authoritative --apcu-autoloader"
;;
run-script)
opts="${opts} --timeout --dev --no-dev --list"
;;
search)
opts="${opts} --only-name --type"
;;
self-update)
opts="${opts} --rollback --clean-backups --no-progress --update-keys --stable --preview --snapshot"
;;
show)
opts="${opts} --all --installed --platform --available --self --name-only --path --tree --latest --outdated --minor-only --direct --strict"
;;
status)
opts="${opts} "
;;
suggests)
opts="${opts} --by-package --by-suggestion --no-dev"
;;
update)
opts="${opts} --prefer-source --prefer-dist --dry-run --dev --no-dev --lock --no-custom-installers --no-autoloader --no-scripts --no-progress --no-suggest --with-dependencies --optimize-autoloader --classmap-authoritative --apcu-autoloader --ignore-platform-reqs --prefer-stable --prefer-lowest --interactive --root-reqs"
;;
validate)
opts="${opts} --no-check-all --no-check-lock --no-check-publish --with-dependencies --strict"
;;
esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
__ltrim_colon_completions "$cur"
return 0;
fi
# completing for a command
if [[ $cur == $com ]]; then
coms="about archive browse clear-cache config create-project depends diagnose dump-autoload exec global help init install licenses list outdated prohibits remove require run-script search self-update show status suggests update validate"
COMPREPLY=($(compgen -W "${coms}" -- ${cur}))
__ltrim_colon_completions "$cur"
return 0
fi
}
complete -o default -F _composer composer

@ -0,0 +1,4 @@
#!/usr/bin/env bash
which register-python-argcomplete > /dev/null \
&& eval "$(register-python-argcomplete conda)" \
|| echo "Please install argcomplete to use conda completion" > /dev/null

@ -0,0 +1,175 @@
# defaults
# Bash command line completion for defaults
#
# Created by Jonathon Mah on 2006-11-08.
# Copyright 2006 Playhaus. All rights reserved.
#
# Version 1.0 (2006-11-08)
_defaults_domains()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep -i "^$cur" )
local IFS=$'\n'
COMPREPLY=( $domains )
if [[ $( echo '-app' | grep "^$cur" ) ]]; then
COMPREPLY[${#COMPREPLY[@]}]="-app"
fi
return 0
}
_defaults()
{
local cur prev host_opts cmds cmd domain keys key_index
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
host_opts='-currentHost -host'
cmds='read read-type write rename delete domains find help'
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $( compgen -W "$host_opts $cmds" -- $cur ) )
return 0
elif [[ $COMP_CWORD -eq 2 ]]; then
if [[ "$prev" == "-currentHost" ]]; then
COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
return 0
elif [[ "$prev" == "-host" ]]; then
return 0
_known_hosts -a
else
_defaults_domains
return 0
fi
elif [[ $COMP_CWORD -eq 3 ]]; then
if [[ ${COMP_WORDS[1]} == "-host" ]]; then
_defaults_domains
return 0
fi
fi
# Both a domain and command have been specified
if [[ ${COMP_WORDS[1]} == [${cmds// /|}] ]]; then
cmd=${COMP_WORDS[1]}
domain=${COMP_WORDS[2]}
key_index=3
if [[ "$domain" == "-app" ]]; then
if [[ $COMP_CWORD -eq 3 ]]; then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[3]}"
key_index=4
fi
elif [[ ${COMP_WORDS[2]} == "-currentHost" ]] && [[ ${COMP_WORDS[2]} == [${cmds// /|}] ]]; then
cmd=${COMP_WORDS[2]}
domain=${COMP_WORDS[3]}
key_index=4
if [[ "$domain" == "-app" ]]; then
if [[ $COMP_CWORD -eq 4 ]]; then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[4]}"
key_index=5
fi
elif [[ ${COMP_WORDS[3]} == "-host" ]] && [[ ${COMP_WORDS[3]} == [${cmds// /|}] ]]; then
cmd=${COMP_WORDS[3]}
domain=${COMP_WORDS[4]}
key_index=5
if [[ "$domain" == "-app" ]]; then
if [[ $COMP_CWORD -eq 5 ]]; then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[5]}"
key_index=6
fi
fi
keys=$( defaults read $domain 2>/dev/null | sed -n -e '/^ [^}) ]/p' | sed -e 's/^ \([^" ]\{1,\}\) = .*$/\1/g' -e 's/^ "\([^"]\{1,\}\)" = .*$/\1/g' | sed -e 's/ /\\ /g' )
case $cmd in
read|read-type)
# Complete key
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
;;
write)
if [[ $key_index -eq $COMP_CWORD ]]; then
# Complete key
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
elif [[ $((key_index+1)) -eq $COMP_CWORD ]]; then
# Complete value type
# Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
local value_types='-string -data -integer -float -boolean -date -array -array-add -dict -dict-add'
local cur_type=$( defaults read-type $domain ${COMP_WORDS[key_index]} 2>/dev/null | sed -e 's/^Type is \(.*\)/-\1/' -e's/dictionary/dict/' | grep "^$cur" )
if [[ $cur_type ]]; then
COMPREPLY=( $cur_type )
else
COMPREPLY=( $( compgen -W "$value_types" -- $cur ) )
fi
elif [[ $((key_index+2)) -eq $COMP_CWORD ]]; then
# Complete value
# Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
COMPREPLY=( $( defaults read $domain ${COMP_WORDS[key_index]} 2>/dev/null | grep -i "^${cur//\\/\\\\}" ) )
fi
;;
rename)
if [[ $key_index -eq $COMP_CWORD ]] ||
[[ $((key_index+1)) -eq $COMP_CWORD ]]; then
# Complete source and destination keys
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
fi
;;
delete)
if [[ $key_index -eq $COMP_CWORD ]]; then
# Complete key
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
fi
;;
esac
return 0
}
complete -F _defaults -o default defaults
# This file is licensed under the BSD license, as follows:
#
# Copyright (c) 2006, Playhaus
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of the Playhaus nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# This software is provided by the copyright holders and contributors "as is"
# and any express or implied warranties, including, but not limited to, the
# implied warranties of merchantability and fitness for a particular purpose are
# disclaimed. In no event shall the copyright owner or contributors be liable
# for any direct, indirect, incidental, special, exemplary, or consequential
# damages (including, but not limited to, procurement of substitute goods or
# services; loss of use, data, or profits; or business interruption) however
# caused and on any theory of liability, whether in contract, strict liability,
# or tort (including negligence or otherwise) arising in any way out of the use
# of this software, even if advised of the possibility of such damage.

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Bash completion support for the 'dirs' plugin (commands G, R).
_dirs-complete() {
local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}"
# parse all defined shortcuts from ~/.dirs
if [ -r "$HOME/.dirs" ]; then
COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}) )
fi
return 0
}
complete -o default -o nospace -F _dirs-complete G R

@ -0,0 +1,72 @@
# #########################################################################
# This bash script adds tab-completion feature to django-admin.py and
# manage.py.
#
# Testing it out without installing
# =================================
#
# To test out the completion without "installing" this, just run this file
# directly, like so:
#
# . ~/path/to/django_bash_completion
#
# Note: There's a dot ('.') at the beginning of that command.
#
# After you do that, tab completion will immediately be made available in your
# current Bash shell. But it won't be available next time you log in.
#
# Installing
# ==========
#
# To install this, point to this file from your .bash_profile, like so:
#
# . ~/path/to/django_bash_completion
#
# Do the same in your .bashrc if .bashrc doesn't invoke .bash_profile.
#
# Settings will take effect the next time you log in.
#
# Uninstalling
# ============
#
# To uninstall, just remove the line from your .bash_profile and .bashrc.
_django_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
DJANGO_AUTO_COMPLETE=1 $1 ) )
}
complete -F _django_completion -o default django-admin.py manage.py django-admin
_python_django_completion()
{
if [[ ${COMP_CWORD} -ge 2 ]]; then
PYTHON_EXE=$( basename -- ${COMP_WORDS[0]} )
echo $PYTHON_EXE | egrep "python([2-9]\.[0-9])?" >/dev/null 2>&1
if [[ $? == 0 ]]; then
PYTHON_SCRIPT=$( basename -- ${COMP_WORDS[1]} )
echo $PYTHON_SCRIPT | egrep "manage\.py|django-admin(\.py)?" >/dev/null 2>&1
if [[ $? == 0 ]]; then
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \
COMP_CWORD=$(( COMP_CWORD-1 )) \
DJANGO_AUTO_COMPLETE=1 ${COMP_WORDS[*]} ) )
fi
fi
fi
}
# Support for multiple interpreters.
unset pythons
if command -v whereis &>/dev/null; then
python_interpreters=$(whereis python | cut -d " " -f 2-)
for python in $python_interpreters; do
pythons="${pythons} $(basename -- $python)"
done
pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
else
pythons=python
fi
complete -F _python_django_completion -o default $pythons

@ -0,0 +1,561 @@
#!bash
#
# bash completion for docker-compose
#
# This work is based on the completion for the docker command.
#
# This script provides completion of:
# - commands and their options
# - service names
# - filepaths
#
# To enable the completions either:
# - place this file in /etc/bash_completion.d
# or
# - copy this file to e.g. ~/.docker-compose-completion.sh and add the line
# below to your .bashrc after bash completion features are loaded
# . ~/.docker-compose-completion.sh
__docker_compose_q() {
docker-compose 2>/dev/null $daemon_options "$@"
}
# Transforms a multiline list of strings into a single line string
# with the words separated by "|".
__docker_compose_to_alternatives() {
local parts=( $1 )
local IFS='|'
echo "${parts[*]}"
}
# Transforms a multiline list of options into an extglob pattern
# suitable for use in case statements.
__docker_compose_to_extglob() {
local extglob=$( __docker_compose_to_alternatives "$1" )
echo "@($extglob)"
}
# suppress trailing whitespace
__docker_compose_nospace() {
# compopt is not available in ancient bash versions
type compopt &>/dev/null && compopt -o nospace
}
# Extracts all service names from the compose file.
___docker_compose_all_services_in_compose_file() {
__docker_compose_q config --services
}
# All services, even those without an existing container
__docker_compose_services_all() {
COMPREPLY=( $(compgen -W "$(___docker_compose_all_services_in_compose_file)" -- "$cur") )
}
# All services that have an entry with the given key in their compose_file section
___docker_compose_services_with_key() {
# flatten sections under "services" to one line, then filter lines containing the key and return section name
__docker_compose_q config \
| sed -n -e '/^services:/,/^[^ ]/p' \
| sed -n 's/^ //p' \
| awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' \
| awk -F: -v key=": +$1:" '$0 ~ key {print $1}'
}
# All services that are defined by a Dockerfile reference
__docker_compose_services_from_build() {
COMPREPLY=( $(compgen -W "$(___docker_compose_services_with_key build)" -- "$cur") )
}
# All services that are defined by an image
__docker_compose_services_from_image() {
COMPREPLY=( $(compgen -W "$(___docker_compose_services_with_key image)" -- "$cur") )
}
# The services for which containers have been created, optionally filtered
# by a boolean expression passed in as argument.
__docker_compose_services_with() {
local containers names
containers="$(__docker_compose_q ps -q)"
names=$(docker 2>/dev/null inspect -f "{{if ${1:-true}}}{{range \$k, \$v := .Config.Labels}}{{if eq \$k \"com.docker.compose.service\"}}{{\$v}}{{end}}{{end}}{{end}}" $containers)
COMPREPLY=( $(compgen -W "$names" -- "$cur") )
}
# The services for which at least one paused container exists
__docker_compose_services_paused() {
__docker_compose_services_with '.State.Paused'
}
# The services for which at least one running container exists
__docker_compose_services_running() {
__docker_compose_services_with '.State.Running'
}
# The services for which at least one stopped container exists
__docker_compose_services_stopped() {
__docker_compose_services_with 'not .State.Running'
}
_docker_compose_build() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--force-rm --help --no-cache --pull" -- "$cur" ) )
;;
*)
__docker_compose_services_from_build
;;
esac
}
_docker_compose_bundle() {
case "$prev" in
--output|-o)
_filedir
return
;;
esac
COMPREPLY=( $( compgen -W "--fetch-digests --help --output -o" -- "$cur" ) )
}
_docker_compose_config() {
COMPREPLY=( $( compgen -W "--help --quiet -q --services" -- "$cur" ) )
}
_docker_compose_create() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--force-recreate --help --no-build --no-recreate" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_docker_compose() {
case "$prev" in
--tlscacert|--tlscert|--tlskey)
_filedir
return
;;
--file|-f)
_filedir "y?(a)ml"
return
;;
$(__docker_compose_to_extglob "$daemon_options_with_args") )
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "$daemon_boolean_options $daemon_options_with_args --help -h --verbose --version -v" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
;;
esac
}
_docker_compose_down() {
case "$prev" in
--rmi)
COMPREPLY=( $( compgen -W "all local" -- "$cur" ) )
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --rmi --volumes -v --remove-orphans" -- "$cur" ) )
;;
esac
}
_docker_compose_events() {
case "$prev" in
--json)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --json" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_exec() {
case "$prev" in
--index|--user)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-d --help --index --privileged -T --user" -- "$cur" ) )
;;
*)
__docker_compose_services_running
;;
esac
}
_docker_compose_help() {
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
}
_docker_compose_kill() {
case "$prev" in
-s)
COMPREPLY=( $( compgen -W "SIGHUP SIGINT SIGKILL SIGUSR1 SIGUSR2" -- "$(echo $cur | tr '[:lower:]' '[:upper:]')" ) )
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help -s" -- "$cur" ) )
;;
*)
__docker_compose_services_running
;;
esac
}
_docker_compose_logs() {
case "$prev" in
--tail)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--follow -f --help --no-color --tail --timestamps -t" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_pause() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_running
;;
esac
}
_docker_compose_port() {
case "$prev" in
--protocol)
COMPREPLY=( $( compgen -W "tcp udp" -- "$cur" ) )
return;
;;
--index)
return;
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --index --protocol" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_ps() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help -q" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_pull() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --ignore-pull-failures" -- "$cur" ) )
;;
*)
__docker_compose_services_from_image
;;
esac
}
_docker_compose_push() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --ignore-push-failures" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_restart() {
case "$prev" in
--timeout|-t)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) )
;;
*)
__docker_compose_services_running
;;
esac
}
_docker_compose_rm() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--force -f --help -v" -- "$cur" ) )
;;
*)
__docker_compose_services_stopped
;;
esac
}
_docker_compose_run() {
case "$prev" in
-e)
COMPREPLY=( $( compgen -e -- "$cur" ) )
__docker_compose_nospace
return
;;
--entrypoint|--name|--user|-u|--workdir|-w)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-d --entrypoint -e --help --name --no-deps --publish -p --rm --service-ports -T --user -u --workdir -w" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_scale() {
case "$prev" in
=)
COMPREPLY=("$cur")
return
;;
--timeout|-t)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) )
;;
*)
COMPREPLY=( $(compgen -S "=" -W "$(___docker_compose_all_services_in_compose_file)" -- "$cur") )
__docker_compose_nospace
;;
esac
}
_docker_compose_start() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_stopped
;;
esac
}
_docker_compose_stop() {
case "$prev" in
--timeout|-t)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) )
;;
*)
__docker_compose_services_running
;;
esac
}
_docker_compose_unpause() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_paused
;;
esac
}
_docker_compose_up() {
case "$prev" in
--timeout|-t)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--abort-on-container-exit --build -d --force-recreate --help --no-build --no-color --no-deps --no-recreate --timeout -t --remove-orphans" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_version() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--short" -- "$cur" ) )
;;
esac
}
_docker_compose() {
local previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob
local commands=(
build
bundle
config
create
down
events
exec
help
kill
logs
pause
port
ps
pull
push
restart
rm
run
scale
start
stop
unpause
up
version
)
# options for the docker daemon that have to be passed to secondary calls to
# docker-compose executed by this script
local daemon_boolean_options="
--skip-hostname-check
--tls
--tlsverify
"
local daemon_options_with_args="
--file -f
--host -H
--project-name -p
--tlscacert
--tlscert
--tlskey
"
COMPREPLY=()
local cur prev words cword
_get_comp_words_by_ref -n : cur prev words cword
# search subcommand and invoke its handler.
# special treatment of some top-level options
local command='docker_compose'
local daemon_options=()
local counter=1
while [ $counter -lt $cword ]; do
case "${words[$counter]}" in
$(__docker_compose_to_extglob "$daemon_boolean_options") )
local opt=${words[counter]}
daemon_options+=($opt)
;;
$(__docker_compose_to_extglob "$daemon_options_with_args") )
local opt=${words[counter]}
local arg=${words[++counter]}
daemon_options+=($opt $arg)
;;
-*)
;;
*)
command="${words[$counter]}"
break
;;
esac
(( counter++ ))
done
local completions_func=_docker_compose_${command//-/_}
declare -F $completions_func >/dev/null && $completions_func
eval "$previous_extglob_setting"
return 0
}
complete -F _docker_compose docker-compose

@ -0,0 +1,252 @@
#
# bash completion file for docker-machine commands
#
# This script provides completion of:
# - commands and their options
# - machine names
# - filepaths
#
# To enable the completions either:
# - place this file in /etc/bash_completion.d
# or
# - copy this file to e.g. ~/.docker-machine-completion.sh and add the line
# below to your .bashrc after bash completion features are loaded
# . ~/.docker-machine-completion.sh
#
_docker_machine_active() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=()
fi
}
_docker_machine_config() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--swarm --help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_create() {
# cheating, b/c there are approximately one zillion options to create
COMPREPLY=($(compgen -W "$(docker-machine create --help | grep '^ -' | sed 's/^ //; s/[^a-z0-9-].*$//')" -- "${cur}"))
}
_docker_machine_env() {
case "${prev}" in
--shell)
# What are the options for --shell?
COMPREPLY=()
;;
*)
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--swarm --shell --unset --no-proxy --help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
esac
}
# See docker-machine-wrapper.bash for the use command
_docker_machine_use() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--swarm --unset --help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_inspect() {
case "${prev}" in
-f|--format)
COMPREPLY=()
;;
*)
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--format --help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
;;
esac
}
_docker_machine_ip() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_kill() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_ls() {
case "${prev}" in
--filter)
COMPREPLY=()
;;
*)
COMPREPLY=($(compgen -W "--quiet --filter --format --timeout --help" -- "${cur}"))
;;
esac
}
_docker_machine_regenerate_certs() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help --force" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_restart() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_rm() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help --force -y" -- "${cur}"))
else
# For rm, it's best to be explicit
COMPREPLY=()
fi
}
_docker_machine_ssh() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_scp() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help --recursive" -- "${cur}"))
else
_filedir
# It would be really nice to ssh to the machine and ls to complete
# remote files.
COMPREPLY=($(compgen -W "$(docker-machine ls -q | sed 's/$/:/')" -- "${cur}") "${COMPREPLY[@]}")
fi
}
_docker_machine_start() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_status() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_stop() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_upgrade() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_url() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_version() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(docker-machine ls -q)" -- "${cur}"))
fi
}
_docker_machine_help() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "${commands[*]}" -- "${cur}"))
fi
}
_docker_machine_docker_machine() {
if [[ " ${wants_file[*]} " =~ " ${prev} " ]]; then
_filedir
elif [[ " ${wants_dir[*]} " =~ " ${prev} " ]]; then
_filedir -d
elif [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "${flags[*]} ${wants_dir[*]} ${wants_file[*]}" -- "${cur}"))
else
COMPREPLY=($(compgen -W "${commands[*]}" -- "${cur}"))
fi
}
_docker_machine() {
COMPREPLY=()
local commands=(active config create env inspect ip kill ls regenerate-certs restart rm ssh scp start status stop upgrade url version help)
local flags=(--debug --native-ssh --github-api-token --bugsnag-api-token --help --version)
local wants_dir=(--storage-path)
local wants_file=(--tls-ca-cert --tls-ca-key --tls-client-cert --tls-client-key)
# Add the use subcommand, if we have an alias loaded
if [[ ${DOCKER_MACHINE_WRAPPED} = true ]]; then
commands=("${commands[@]}" use)
fi
local cur prev words cword
_get_comp_words_by_ref -n : cur prev words cword
local i
local command=docker-machine
for (( i=1; i < ${cword}; ++i)); do
local word=${words[i]}
if [[ " ${wants_file[*]} ${wants_dir[*]} " =~ " ${word} " ]]; then
# skip the next option
(( ++i ))
elif [[ " ${commands[*]} " =~ " ${word} " ]]; then
command=${word}
fi
done
local completion_func=_docker_machine_"${command//-/_}"
if declare -F "${completion_func}" > /dev/null; then
${completion_func}
fi
return 0
}
complete -F _docker_machine docker-machine

File diff suppressed because it is too large Load Diff

@ -0,0 +1,37 @@
#!/usr/bin/env bash
#
# bash completion support for Drush:
# https://github.com/drush-ops/drush
#
# Originally from:
# http://github.com/drush-ops/drush/blob/master/drush.complete.sh
# Ensure drush is available.
which drush &> /dev/null || alias drush &> /dev/null || return
__drush_ps1() {
f="${TMPDIR:-/tmp/}/drush-env/drush-drupal-site-$$"
if [ -f $f ]
then
__DRUPAL_SITE=$(cat "$f")
else
__DRUPAL_SITE="$DRUPAL_SITE"
fi
[[ -n "$__DRUPAL_SITE" ]] && printf "${1:- (%s)}" "$__DRUPAL_SITE"
}
# Completion function, uses the "drush complete" command to retrieve
# completions for a specific command line COMP_WORDS.
_drush_completion() {
# Set IFS to newline (locally), since we only use newline separators, and
# need to retain spaces (or not) after completions.
local IFS=$'\n'
# The '< /dev/null' is a work around for a bug in php libedit stdin handling.
# Note that libedit in place of libreadline in some distributions. See:
# https://bugs.launchpad.net/ubuntu/+source/php5/+bug/322214
COMPREPLY=( $(drush --early=includes/complete.inc "${COMP_WORDS[@]}" < /dev/null 2> /dev/null) )
}
# Register our completion function. We include common short aliases for Drush.
complete -o bashdefault -o default -o nospace -F _drush_completion d dr drush drush5 drush6 drush6 drush.php

@ -0,0 +1,133 @@
#!/usr/bin/env bash
#
# Bash completion support for Fabric (http://fabfile.org/)
#
#
# Copyright (C) 2011 by Konstantin Bakulin
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Thanks to:
# - Adam Vandenberg,
# https://github.com/adamv/dotfiles/blob/master/completion_scripts/fab_completion.bash
#
# - Enrico Batista da Luz,
# https://github.com/ricobl/dotfiles/blob/master/bin/fab_bash_completion
#
# Use cache files for fab tasks or not.
# If set to "false" command "fab --shortlist" will be executed every time.
export FAB_COMPLETION_CACHE_TASKS=true
# File name where tasks cache will be stored (in current dir).
export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~"
# Set command to get time of last file modification as seconds since Epoch
case `uname` in
Darwin|FreeBSD)
__FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'"
;;
*)
__FAB_COMPLETION_MTIME_COMMAND="stat -c '%Y'"
;;
esac
#
# Get time of last fab cache file modification as seconds since Epoch
#
function __fab_chache_mtime() {
${__FAB_COMPLETION_MTIME_COMMAND} \
$FAB_COMPLETION_CACHED_TASKS_FILENAME | xargs -n 1 expr
}
#
# Get time of last fabfile file/module modification as seconds since Epoch
#
function __fab_fabfile_mtime() {
local f="fabfile"
if [[ -e "$f.py" ]]; then
${__FAB_COMPLETION_MTIME_COMMAND} "$f.py" | xargs -n 1 expr
else
# Suppose that it's a fabfile dir
find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \
| xargs -n 1 expr | sort -n -r | head -1
fi
}
#
# Completion for "fab" command
#
function __fab_completion() {
# Return if "fab" command doesn't exists
[[ -e `which fab 2> /dev/null` ]] || return 0
# Variables to hold the current word and possible matches
local cur="${COMP_WORDS[COMP_CWORD]}"
local opts=()
# Generate possible matches and store them in variable "opts"
case "${cur}" in
-*)
if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then
export __FAB_COMPLETION_LONG_OPT=$(
fab --help | egrep -o "\-\-[A-Za-z_\-]+\=?" | sort -u)
fi
opts="${__FAB_COMPLETION_LONG_OPT}"
;;
# Completion for short options is not nessary.
# It's left here just for history.
# -*)
# if [[ -z "${__FAB_COMPLETION_SHORT_OPT}" ]]; then
# export __FAB_COMPLETION_SHORT_OPT=$(
# fab --help | egrep -o "^ +\-[A-Za-z_\]" | sort -u)
# fi
# opts="${__FAB_COMPLETION_SHORT_OPT}"
# ;;
*)
# If "fabfile.py" or "fabfile" dir with "__init__.py" file exists
local f="fabfile"
if [[ -e "$f.py" || (-d "$f" && -e "$f/__init__.py") ]]; then
# Build a list of the available tasks
if $FAB_COMPLETION_CACHE_TASKS; then
# If use cache
if [[ ! -s ${FAB_COMPLETION_CACHED_TASKS_FILENAME} ||
$(__fab_fabfile_mtime) -gt $(__fab_chache_mtime) ]]; then
fab --shortlist > ${FAB_COMPLETION_CACHED_TASKS_FILENAME} \
2> /dev/null
fi
opts=$(cat ${FAB_COMPLETION_CACHED_TASKS_FILENAME})
else
# Without cache
opts=$(fab --shortlist 2> /dev/null)
fi
fi
;;
esac
# Set possible completions
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -o default -o nospace -F __fab_completion fab

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Completion for gem
_installcomp() {
if [ -z "$REMOTE_GEMS" ]
then
REMOTE_GEMS=( $(gem list --remote --no-versions | tr '\n' ' ') )
fi
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "${REMOTE_GEMS[*]}" -- $cur) )
}
_uninstallcomp() {
if [ -z "$LOCAL_GEMS" ]
then
LOCAL_GEMS=( $(gem list --no-versions | sed 's/\*\*\* LOCAL GEMS \*\*\*//' | tr '\n' ' ') )
fi
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "${LOCAL_GEMS[*]}" -- $cur) )
}
_gem() {
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
case $prev in
install)
_installcomp
return 0
;;
uninstall)
_uninstallcomp
return 0
;;
esac
local commands=(build cert check cleanup contents dependency environment fetch generate_index help install list lock outdated owner pristine push query rdoc search server sources specification stale uninstall unpack update which)
COMPREPLY=( $(compgen -W "${commands[*]}" -- $cur) )
}
complete -F _gem gem

366
completion/gh.completion.sh Normal file

@ -0,0 +1,366 @@
# hub tab-completion script for bash.
# This script complements the completion script that ships with git.
# Check that git tab completion is available
if declare -F _git > /dev/null; then
# Duplicate and rename the 'list_all_commands' function
eval "$(declare -f __git_list_all_commands | \
sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')"
# Wrap the 'list_all_commands' function with extra hub commands
__git_list_all_commands() {
cat <<-EOF
alias
pull-request
fork
create
browse
compare
ci-status
release
issue
update
EOF
__git_list_all_commands_without_hub
}
# Ensure cached commands are cleared
__git_all_commands=""
##########################
# hub command completions
##########################
# hub alias [-s] [SHELL]
_git_alias() {
local i c=2 s=-s sh shells="bash zsh sh ksh csh fish"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-s)
unset s
;;
*)
for sh in $shells; do
if [ "$sh" = "$i" ]; then
unset shells
break
fi
done
;;
esac
((c++))
done
__gitcomp "$s $shells"
}
# hub browse [-u] [--|[USER/]REPOSITORY] [SUBPAGE]
_git_browse() {
local i c=2 u=-u repo subpage
local subpages_="commits issues tree wiki pulls branches stargazers
contributors network network/ graphs graphs/"
local subpages_network="members"
local subpages_graphs="commit-activity code-frequency punch-card"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$repo" ]; then
repo=$i
else
subpage=$i
fi
;;
esac
((c++))
done
if [ -z "$repo" ]; then
__gitcomp "$u -- $(__hub_github_repos '\p')"
elif [ -z "$subpage" ]; then
case "$cur" in
*/*)
local pfx="${cur%/*}" cur_="${cur#*/}"
local subpages_var="subpages_$pfx"
__gitcomp "${!subpages_var}" "$pfx/" "$cur_"
;;
*)
__gitcomp "$u ${subpages_}"
;;
esac
else
__gitcomp "$u"
fi
}
# hub compare [-u] [USER[/REPOSITORY]] [[START...]END]
_git_compare() {
local i c=$((cword - 1)) u=-u user remote owner repo arg_repo rev
while [ $c -gt 1 ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$rev" ]; then
# Even though the logic below is able to complete both user/repo
# and revision in the right place, when there is only one argument
# (other than -u) in the command, that argument will be taken as
# revision. For example:
# $ hub compare -u upstream
# > https://github.com/USER/REPO/compare/upstream
if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then
arg_repo=$i
else
rev=$i
fi
elif [ -z "$arg_repo" ]; then
arg_repo=$i
fi
;;
esac
((c--))
done
# Here we want to find out the git remote name of user/repo, in order to
# generate an appropriate revision list
if [ -z "$arg_repo" ]; then
user=$(__hub_github_user)
if [ -z "$user" ]; then
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
if [ "$remote" = origin ]; then
break
fi
done
else
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
owner=${repo%%/*}
if [ "$user" = "$owner" ]; then
break
fi
done
fi
else
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
owner=${repo%%/*}
case "$arg_repo" in
"$repo"|"$owner")
break
;;
esac
done
fi
local pfx cur_="$cur"
case "$cur_" in
*..*)
pfx="${cur_%%..*}..."
cur_="${cur_##*..}"
__gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_"
;;
*)
if [ -z "${arg_repo}${rev}" ]; then
__gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)"
elif [ -z "$rev" ]; then
__gitcomp "$u $(__hub_revlist $remote)"
else
__gitcomp "$u"
fi
;;
esac
}
# hub create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE]
_git_create() {
local i c=2 name repo flags="-p -d -h"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-d|-h)
((c++))
flags=${flags/$i/}
;;
-p)
flags=${flags/$i/}
;;
*)
name=$i
;;
esac
((c++))
done
if [ -z "$name" ]; then
repo=$(basename "$(pwd)")
fi
case "$prev" in
-d|-h)
COMPREPLY=()
;;
-p|*)
__gitcomp "$repo $flags"
;;
esac
}
# hub fork [--no-remote]
_git_fork() {
local i c=2 remote=yes
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--no-remote)
unset remote
;;
esac
((c++))
done
if [ -n "$remote" ]; then
__gitcomp "--no-remote"
fi
}
# hub pull-request [-f] [-m <MESSAGE>|-F <FILE>|-i <ISSUE>|<ISSUE-URL>] [-b <BASE>] [-h <HEAD>]
_git_pull_request() {
local i c=2 flags="-f -m -F -i -b -h"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-m|-F|-i|-b|-h)
((c++))
flags=${flags/$i/}
;;
-f)
flags=${flags/$i/}
;;
esac
((c++))
done
case "$prev" in
-i)
COMPREPLY=()
;;
-b|-h)
# (Doesn't seem to need this...)
# Uncomment the following line when 'owner/repo:[TAB]' misbehaved
#_get_comp_words_by_ref -n : cur
__gitcomp_nl "$(__hub_heads)"
# __ltrim_colon_completions "$cur"
;;
-F)
COMPREPLY=( "$cur"* )
;;
-f|*)
__gitcomp "$flags"
;;
esac
}
###################
# Helper functions
###################
# __hub_github_user [HOST]
# Return $GITHUB_USER or the default github user defined in hub config
# HOST - Host to be looked-up in hub config. Default is "github.com"
__hub_github_user() {
if [ -n "$GITHUB_USER" ]; then
echo $GITHUB_USER
return
fi
local line h k v host=${1:-github.com} config=${HUB_CONFIG:-~/.config/gh}
if [ -f "$config" ]; then
while read line; do
if [ "$line" = "---" ]; then
continue
fi
k=${line%%:*}
v=${line#*:}
if [ -z "$v" ]; then
if [ "$h" = "$host" ]; then
break
fi
h=$k
continue
fi
k=${k#* }
v=${v#* }
if [ "$h" = "$host" ] && [ "$k" = "user" ]; then
echo "$v"
break
fi
done < "$config"
fi
}
# __hub_github_repos [FORMAT]
# List all github hosted repository
# FORMAT - Format string contains multiple of these:
# \m remote
# \p owner/repo
# \o owner
# escaped characters (\n, \t ...etc) work
# If omitted, prints all github repos in the format of "remote:owner/repo"
__hub_github_repos() {
local f format=$1
if [ -z "$(__gitdir)" ]; then
return
fi
if [ -z "$format" ]; then
format='\1:\2'
else
format=${format//\m/\1}
format=${format//\p/\2}
format=${format//\o/\3}
fi
command git config --get-regexp 'remote\.[^.]*\.url' |
grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#'
}
# __hub_heads
# List all local "branch", and remote "owner/repo:branch"
__hub_heads() {
local i remote repo branch dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/heads/"
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read branch; do
echo "${repo}:${branch#${remote}/}"
done
done
fi
}
# __hub_revlist [REMOTE]
# List all tags, and branches under REMOTE, without the "remote/" prefix
# REMOTE - Remote name to search branches from. Default is "origin"
__hub_revlist() {
local i remote=${1:-origin} dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read i; do
echo "${i#${remote}/}"
done
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/tags/"
fi
}
# Enable completion for hub even when not using the alias
complete -o bashdefault -o default -o nospace -F _git gh 2>/dev/null \
|| complete -o default -o nospace -F _git gh
fi

2776
completion/git.completion.sh Normal file

File diff suppressed because it is too large Load Diff

@ -0,0 +1,177 @@
#!bash
#
# git-flow-completion
# ===================
#
# Bash completion support for [git-flow](http://github.com/nvie/gitflow)
#
# The contained completion routines provide support for completing:
#
# * git-flow init and version
# * feature, hotfix and release branches
# * remote feature branch names (for `git-flow feature track`)
#
#
# Installation
# ------------
#
# To achieve git-flow completion nirvana:
#
# 0. Install git-completion.
#
# 1. Install this file. Either:
#
# a. Place it in a `bash-completion.d` folder:
#
# * /etc/bash-completion.d
# * /usr/local/etc/bash-completion.d
# * ~/bash-completion.d
#
# b. Or, copy it somewhere (e.g. ~/.git-flow-completion.sh) and put the following line in
# your .bashrc:
#
# source ~/.git-flow-completion.sh
#
# 2. If you are using Git < 1.7.1: Edit git-completion.sh and add the following line to the giant
# $command case in _git:
#
# flow) _git_flow ;;
#
#
# The Fine Print
# --------------
#
# Copyright (c) 2010 [Justin Hileman](http://justinhileman.com)
#
# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
_git_flow ()
{
local subcommands="init feature release hotfix"
local subcommand="$(__git_find_subcommand "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
feature)
__git_flow_feature
return
;;
release)
__git_flow_release
return
;;
hotfix)
__git_flow_hotfix
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_feature ()
{
local subcommands="list start finish publish track diff rebase checkout pull"
local subcommand="$(__git_find_subcommand "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
pull)
__gitcomp "$(__git_remotes)"
return
;;
checkout|finish|diff|rebase)
__gitcomp "$(__git_flow_list_features)"
return
;;
publish)
__gitcomp "$(comm -23 <(__git_flow_list_features) <(__git_flow_list_remote_features))"
return
;;
track)
__gitcomp "$(__git_flow_list_remote_features)"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_list_features ()
{
git flow feature list 2> /dev/null | tr -d ' |*'
}
__git_flow_list_remote_features ()
{
git branch -r 2> /dev/null | grep "origin/$(__git_flow_feature_prefix)" | awk '{ sub(/^origin\/$(__git_flow_feature_prefix)/, "", $1); print }'
}
__git_flow_feature_prefix ()
{
git config gitflow.prefix.feature 2> /dev/null || echo "feature/"
}
__git_flow_release ()
{
local subcommands="list start finish"
local subcommand="$(__git_find_subcommand "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
__gitcomp "$(__git_flow_list_releases)"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_list_releases ()
{
git flow release list 2> /dev/null
}
__git_flow_hotfix ()
{
local subcommands="list start finish"
local subcommand="$(__git_find_subcommand "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
__gitcomp "$(__git_flow_list_hotfixes)"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_list_hotfixes ()
{
git flow hotfix list 2> /dev/null
}
# temporarily wrap __git_find_on_cmdline() for backwards compatibility
if [ -z "`type -t __git_find_subcommand`" ]; then
alias __git_find_subcommand=__git_find_on_cmdline
fi

@ -0,0 +1,510 @@
#!bash
#
# git-flow-completion
# ===================
#
# Bash completion support for [git-flow (AVH Edition)](http://github.com/petervanderdoes/gitflow)
#
# The contained completion routines provide support for completing:
#
# * git-flow init and version
# * feature, hotfix and release branches
# * remote feature, hotfix and release branch names
#
#
# Installation
# ------------
#
# To achieve git-flow completion nirvana:
#
# 0. Install git-completion.
#
# 1. Install this file. Either:
#
# a. Place it in a `bash-completion.d` folder:
#
# * /etc/bash-completion.d
# * /usr/local/etc/bash-completion.d
# * ~/bash-completion.d
#
# b. Or, copy it somewhere (e.g. ~/.git-flow-completion.sh) and put the following line in
# your .bashrc:
#
# source ~/.git-flow-completion.sh
#
# 2. If you are using Git < 1.7.1: Edit git-completion.sh and add the following line to the giant
# $command case in _git:
#
# flow) _git_flow ;;
#
#
# The Fine Print
# --------------
#
# Author:
# Copyright 2012-2013 Peter van der Does.
#
# Original Author:
# Copyright (c) 2011 [Justin Hileman](http://justinhileman.com)
#
# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
__git_flow_config_file_options="
--local --global --system --file=
"
_git_flow ()
{
local subcommands="init feature release hotfix support help version config finish delete publish rebase"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
init)
__git_flow_init
return
;;
feature)
__git_flow_feature
return
;;
release)
__git_flow_release
return
;;
hotfix)
__git_flow_hotfix
return
;;
support)
__git_flow_support
return
;;
config)
__git_flow_config
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_init ()
{
local subcommands="help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
fi
case "$cur" in
--*)
__gitcomp "
--nodefaults --defaults
--noforce --force
$__git_flow_config_file_options
"
return
;;
esac
}
__git_flow_feature ()
{
local subcommands="list start finish publish track diff rebase checkout pull help delete"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
pull)
__gitcomp_nl "$(__git_remotes)"
return
;;
checkout)
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--norebase --rebase
--nopreserve-merges --preserve-merges
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--nosquash --squash
--no-ff
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
diff)
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'feature')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'feature')"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_release ()
{
local subcommands="list start finish track publish help delete"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--sign
--signingkey
--message
--nomessagefile --messagefile=
--nopush --push
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--notag --tag
--nonobackmerge --nobackmerge
--nosquash --squash
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'release')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'release')"
return
;;
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_hotfix ()
{
local subcommands="list start finish track publish help delete"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--sign
--signingkey
--message
--nomessagefile --messagefile=
--nopush --push
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--notag --tag
--nonobackmerge --nobackmerge
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'hotfix')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'hotfix')"
return
;;
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_support ()
{
local subcommands="list start help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'support')"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_config ()
{
local subcommands="list set base"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
set)
case "$cur" in
--*)
__gitcomp "
$__git_flow_config_file_options
"
return
;;
esac
__gitcomp "
master develop
feature hotfix release support
versiontagprefix
"
return
;;
base)
case "$cur" in
--*)
__gitcomp "
set get
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches)"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_prefix ()
{
case "$1" in
feature|release|hotfix|support)
git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/"
return
;;
esac
}
__git_flow_list_local_branches ()
{
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref#$prefix}"
echo "$ref"
done | sort
else
git for-each-ref --format="ref=%(refname:short)" refs/heads/ | sort
fi
}
__git_flow_list_remote_branches ()
{
local prefix="$(__git_flow_prefix $1)"
local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")"
git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
echo "$ref"
done | sort
}
__git_flow_list_branches ()
{
local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")"
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
echo "$ref"
done | sort
else
git for-each-ref --format="%(refname:short)" refs/heads/ refs/remotes/$origin | sort
fi
}
# alias __git_find_on_cmdline for backwards compatibility
if [ -z "`type -t __git_find_on_cmdline`" ]; then
alias __git_find_on_cmdline=__git_find_subcommand
fi

281
completion/go.completion.sh Normal file

@ -0,0 +1,281 @@
#!/usr/bin/env bash
# bash completion for go tool
# https://github.com/thomasf/go-bash-completion
# install in /etc/bash_completion.d/ or your personal directory
complete -f -X '!*.8' 8l
complete -f -X '!*.6' 6l
complete -f -X '!*.5' 5l
complete -f -X '!*.go' 8g 6g 5g gofmt gccgo
_go_clear_cache() {
unset _go_imports
}
_go_importpath_cache() {
if [ -z "$_go_imports" ]; then
_go_imports=$(go list all 2>/dev/null)
export _go_imports
fi
}
_go_importpath()
{
echo "$(compgen -W "$_go_imports" -- "$1")"
}
_go()
{
# TODO: Only allow flags before other arguments. run already does
# this.
local cur=`_get_cword`
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local cmd="${COMP_WORDS[1]}"
local cmds="build clean doc env fix fmt get
install list run test tool version vet"
local addhelp="gopath importpath remote
testflag testfunc"
local other="help"
local env_vars="GOARCH GOBIN GOEXE GOHOSTARCH GOHOSTOS GOOS GOPATH GORACE
GOROOT GOTOOLDIR GO15VENDOREXPERIMENT CC GOGCCFLAGS CXX CGO_ENABLED"
if [ "$COMP_CWORD" == 1 ]; then
for opt in $cmds; do
if [[ "$opt" == "$cmd" ]]; then
COMPREPLY=("$opt")
return
fi
done
fi
case "$cmd" in
'build')
case "$prev" in
'-o')
_filedir
;;
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-a -n -o -p -v -x" -- "$cur"))
else
local found=0
for ((i=0; i < ${#COMP_WORDS[@]}; i++)); do
case "$i" in
0|1|"$COMP_CWORD")
continue
;;
esac
local opt="${COMP_WORDS[i]}"
if [[ "$opt" != -* ]]; then
if [[ "$opt" == *.go && -f "$opt" ]]; then
found=1
break
else
found=2
break
fi
fi
done
case "$found" in
0)
_filedir go
_go_importpath_cache
COMPREPLY+=(`_go_importpath "$cur"`)
;;
1)
_filedir go
;;
2)
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
esac
fi
;;
esac
;;
'clean')
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-i -r -n -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
'doc')
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
'env')
COMPREPLY=($(compgen -W "$env_vars" -- "$cur"))
;;
'fix')
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
'fmt')
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
'get')
case "$prev" in
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-a -d -fix -n -p -u -v -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'install')
case "$prev" in
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-a -n -p -v -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'list')
case "$prev" in
'-f')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-e -f -json" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'run')
if [[ "$cur" == -* && "$prev" != *.go ]]; then
COMPREPLY=($(compgen -W "-a -n -x" -- "$cur"))
else
_filedir
fi
;;
'test') # TODO: Support for testflags.
case "$prev" in
'-file')
_filedir go
;;
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-c -file -i -p -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'tool')
if [ "$COMP_CWORD" == 2 ]; then
COMPREPLY=($(compgen -W "$(go tool)" -- "$cur"))
else
case "${COMP_WORDS[2]}" in
[568]a) # TODO: Implement something.
#_go_tool_568a
;;
[568]c) # TODO: Implement something.
#_go_tool_568c
;;
[568]g) # TODO: Implement something.
#_go_tool_568g
;;
[568]l) # TODO: Implement something.
#_go_tool_568l
;;
'api') # TODO: Implement something.
#_go_tool_api
;;
'cgo') # TODO: Implement something.
#_go_tool_cgo
;;
'cov') # TODO: Implement something.
#_go_tool_cov
;;
'dist') # TODO: Implement something.
#_go_tool_dist
;;
'ebnflint') # TODO: Implement something.
#_go_tool_ebnflint
;;
'fix') # TODO: Implement something.
#_go_tool_fix
;;
'gotype') # TODO: Implement something.
#_go_tool_gotype
;;
'nm') # TODO: Implement something.
#_go_tool_nm
;;
'pack') # TODO: Implement something.
#_go_tool_pack
;;
'pprof') # TODO: Implement something.
#_go_tool_pprof
;;
'prof') # TODO: Implement something.
#_go_tool_prof
;;
'vet') # TODO: Implement something.
#_go_tool_vet
;;
'yacc') # TODO: Implement something.
#_go_tool_yacc
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "${COMPREPLY[*]} -h" -- "$cur"))
fi
fi
;;
'version')
;;
'vet')
if [[ "$cur" == -* ]]; then
:
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
'help')
if [ "$COMP_CWORD" == 2 ]; then
COMPREPLY=($(compgen -W "$cmds $addhelp" -- "$cur"))
fi
;;
*)
if [ "$COMP_CWORD" == 1 ]; then
COMPREPLY=($(compgen -W "$cmds $other" -- "$cur"))
else
_filedir
fi
;;
esac
}
complete $filenames -F _go go
# vim:ts=2 sw=2 et syn=sh

@ -0,0 +1,50 @@
function __gradle {
local cur=${COMP_WORDS[COMP_CWORD]}
local tasks=''
local cache_dir="$HOME/.gradle/completion_cache"
case $OSTYPE in
darwin*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5 -q | md5 -q"
;;
*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5sum | md5sum | cut -d ' ' -f 1"
;;
esac
local parsing_command="gradle --console=plain --quiet tasks | grep -v Rules | sed -nE -e 's/^([a-zA-Z]+)($| - .+)/\1/p'"
mkdir -p "${cache_dir}"
local gradle_files_checksum='no_cache_file'
if [[ -f build.gradle ]]; then
gradle_files_checksum="$(eval "${checksum_command}")"
if [[ -f "${cache_dir}/${gradle_files_checksum}" ]]; then
newest_gradle_file="$(find . -type f -name build.gradle -newer "${cache_dir}/${gradle_files_checksum}")"
if [ -n "${newest_gradle_file}" ]; then
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
else
tasks="$(cat "${cache_dir}/${gradle_files_checksum}")"
touch "${cache_dir}/${gradle_files_checksum}"
fi
else
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
fi
else
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
fi
COMPREPLY=( $(compgen -W "${tasks}" -- "${cur}") )
}
function __clear_gradle_cache {
local cache_dir="$HOME/.gradle/completion_cache"
[[ -d "${cache_dir}" ]] && find "${cache_dir}" -type f -mtime +7 -exec rm -f {} \;
}
__clear_gradle_cache
complete -F __gradle gradle
complete -F __gradle gradlew
complete -F __gradle ./gradlew

@ -0,0 +1,49 @@
#!/bin/bash
# grunt-cli
# http://gruntjs.com/
#
# Copyright (c) 2012 Tyler Kellen, contributors
# Licensed under the MIT license.
# https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
# Usage:
#
# To enable bash <tab> completion for grunt, add the following line (minus the
# leading #, which is the bash comment character) to your ~/.bashrc file:
#
# eval "$(grunt --completion=bash)"
# Search the current directory and all parent directories for a gruntfile.
function _grunt_gruntfile() {
local curpath="$PWD"
while [[ "$curpath" ]]; do
for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do
if [[ -e "$gruntfile" ]]; then
echo "$gruntfile"
return
fi
done
curpath="${curpath%/*}"
done
return 1
}
# Enable bash autocompletion.
function _grunt_completions() {
# The currently-being-completed word.
local cur="${COMP_WORDS[COMP_CWORD]}"
# The current gruntfile, if it exists.
local gruntfile="$(_grunt_gruntfile)"
# The current grunt version, available tasks, options, etc.
local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
# Options and tasks.
local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
# Only add -- or - options if the user has started typing -
[[ "$cur" == -* ]] && compls="$compls $opts"
# Tell complete what stuff to show.
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
}
complete -o default -F _grunt_completions grunt

@ -0,0 +1,23 @@
#!/bin/bash
# Borrowed from grunt-cli
# http://gruntjs.com/
#
# Copyright (c) 2012 Tyler Kellen, contributors
# Licensed under the MIT license.
# https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
# Usage:
#
# To enable bash <tab> completion for gulp, add the following line (minus the
# leading #, which is the bash comment character) to your ~/.bashrc file:
#
# eval "$(gulp --completion=bash)"
# Enable bash autocompletion.
function _gulp_completions() {
# The currently-being-completed word.
local cur="${COMP_WORDS[COMP_CWORD]}"
#Grab tasks
local compls=$(gulp --tasks-simple)
# Tell complete what stuff to show.
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
}
complete -o default -F _gulp_completions gulp

@ -0,0 +1,60 @@
# Bash completion script for homesick
#
# The homebrew bash completion script was used as inspiration.
# Originally from https://github.com/liborw/homesick-completion
_homesick_complete()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
local options="--skip --force --pretend --quiet"
local actions="cd clone commit destroy diff generate help list open pull push rc show_path status symlink track unlink version"
local repos=$(\ls ~/.homesick/repos)
# Subcommand list
[[ ${COMP_CWORD} -eq 1 ]] && {
COMPREPLY=( $(compgen -W "${options} ${actions}" -- ${cur}) )
return
}
# Find the first non-switch word
local prev_index=1
local prev="${COMP_WORDS[prev_index]}"
while [[ $prev == -* ]]; do
prev_index=$((++prev_index))
prev="${COMP_WORDS[prev_index]}"
done
# Find the number of non-"--" commands
local num=0
for word in ${COMP_WORDS[@]}
do
if [[ $word != -* ]]; then
num=$((++num))
fi
done
case "$prev" in
# Commands that take a castle
cd|commit|destroy|diff|open|pull|push|rc|show_path|status|symlink|unlink)
COMPREPLY=( $(compgen -W "${repos}" -- ${cur}) )
return
;;
# Commands that take command
help)
COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
return
;;
# Track command take file and repo
track)
if [[ "$num" -eq 2 ]]; then
COMPREPLY=( $(compgen -X -f ${cur}) )
elif [[ "$num" -ge 3 ]]; then
COMPREPLY=( $(compgen -W "${repos}" -- ${cur}) )
fi
return
;;
esac
}
complete -o bashdefault -o default -F _homesick_complete homesick

@ -0,0 +1,367 @@
# hub tab-completion script for bash.
# This script complements the completion script that ships with git.
# If there is no git tab completion, but we have the _completion loader try to load it
if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; then
_completion_loader git
fi
# Check that git tab completion is available
if declare -F _git > /dev/null; then
# Duplicate and rename the 'list_all_commands' function
eval "$(declare -f __git_list_all_commands | \
sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')"
# Wrap the 'list_all_commands' function with extra hub commands
__git_list_all_commands() {
cat <<-EOF
alias
pull-request
fork
create
browse
compare
ci-status
EOF
__git_list_all_commands_without_hub
}
# Ensure cached commands are cleared
__git_all_commands=""
##########################
# hub command completions
##########################
# hub alias [-s] [SHELL]
_git_alias() {
local i c=2 s=-s sh shells="bash zsh sh ksh csh fish"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-s)
unset s
;;
*)
for sh in $shells; do
if [ "$sh" = "$i" ]; then
unset shells
break
fi
done
;;
esac
((c++))
done
__gitcomp "$s $shells"
}
# hub browse [-u] [--|[USER/]REPOSITORY] [SUBPAGE]
_git_browse() {
local i c=2 u=-u repo subpage
local subpages_="commits issues tree wiki pulls branches stargazers
contributors network network/ graphs graphs/"
local subpages_network="members"
local subpages_graphs="commit-activity code-frequency punch-card"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$repo" ]; then
repo=$i
else
subpage=$i
fi
;;
esac
((c++))
done
if [ -z "$repo" ]; then
__gitcomp "$u -- $(__hub_github_repos '\p')"
elif [ -z "$subpage" ]; then
case "$cur" in
*/*)
local pfx="${cur%/*}" cur_="${cur#*/}"
local subpages_var="subpages_$pfx"
__gitcomp "${!subpages_var}" "$pfx/" "$cur_"
;;
*)
__gitcomp "$u ${subpages_}"
;;
esac
else
__gitcomp "$u"
fi
}
# hub compare [-u] [USER[/REPOSITORY]] [[START...]END]
_git_compare() {
local i c=$((cword - 1)) u=-u user remote owner repo arg_repo rev
while [ $c -gt 1 ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$rev" ]; then
# Even though the logic below is able to complete both user/repo
# and revision in the right place, when there is only one argument
# (other than -u) in the command, that argument will be taken as
# revision. For example:
# $ hub compare -u upstream
# > https://github.com/USER/REPO/compare/upstream
if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then
arg_repo=$i
else
rev=$i
fi
elif [ -z "$arg_repo" ]; then
arg_repo=$i
fi
;;
esac
((c--))
done
# Here we want to find out the git remote name of user/repo, in order to
# generate an appropriate revision list
if [ -z "$arg_repo" ]; then
user=$(__hub_github_user)
if [ -z "$user" ]; then
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
if [ "$remote" = origin ]; then
break
fi
done
else
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
owner=${repo%%/*}
if [ "$user" = "$owner" ]; then
break
fi
done
fi
else
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
owner=${repo%%/*}
case "$arg_repo" in
"$repo"|"$owner")
break
;;
esac
done
fi
local pfx cur_="$cur"
case "$cur_" in
*..*)
pfx="${cur_%%..*}..."
cur_="${cur_##*..}"
__gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_"
;;
*)
if [ -z "${arg_repo}${rev}" ]; then
__gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)"
elif [ -z "$rev" ]; then
__gitcomp "$u $(__hub_revlist $remote)"
else
__gitcomp "$u"
fi
;;
esac
}
# hub create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE]
_git_create() {
local i c=2 name repo flags="-p -d -h"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-d|-h)
((c++))
flags=${flags/$i/}
;;
-p)
flags=${flags/$i/}
;;
*)
name=$i
;;
esac
((c++))
done
if [ -z "$name" ]; then
repo=$(basename "$(pwd)")
fi
case "$prev" in
-d|-h)
COMPREPLY=()
;;
-p|*)
__gitcomp "$repo $flags"
;;
esac
}
# hub fork [--no-remote]
_git_fork() {
local i c=2 remote=yes
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--no-remote)
unset remote
;;
esac
((c++))
done
if [ -n "$remote" ]; then
__gitcomp "--no-remote"
fi
}
# hub pull-request [-f] [-m <MESSAGE>|-F <FILE>|-i <ISSUE>|<ISSUE-URL>] [-b <BASE>] [-h <HEAD>] [-a <USER>] [-M <MILESTONE>] [-l <LABELS>]
_git_pull_request() {
local i c=2 flags="-f -m -F -i -b -h -a -M -l"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-m|-F|-i|-b|-h|-a|-M|-l)
((c++))
flags=${flags/$i/}
;;
-f)
flags=${flags/$i/}
;;
esac
((c++))
done
case "$prev" in
-i)
COMPREPLY=()
;;
-b|-h|-a|-M|-l)
# (Doesn't seem to need this...)
# Uncomment the following line when 'owner/repo:[TAB]' misbehaved
#_get_comp_words_by_ref -n : cur
__gitcomp_nl "$(__hub_heads)"
# __ltrim_colon_completions "$cur"
;;
-F)
COMPREPLY=( "$cur"* )
;;
-f|*)
__gitcomp "$flags"
;;
esac
}
###################
# Helper functions
###################
# __hub_github_user [HOST]
# Return $GITHUB_USER or the default github user defined in hub config
# HOST - Host to be looked-up in hub config. Default is "github.com"
__hub_github_user() {
if [ -n "$GITHUB_USER" ]; then
echo $GITHUB_USER
return
fi
local line h k v host=${1:-github.com} config=${HUB_CONFIG:-~/.config/hub}
if [ -f "$config" ]; then
while read line; do
if [ "$line" = "---" ]; then
continue
fi
k=${line%%:*}
v=${line#*:}
if [ -z "$v" ]; then
if [ "$h" = "$host" ]; then
break
fi
h=$k
continue
fi
k=${k#* }
v=${v#* }
if [ "$h" = "$host" ] && [ "$k" = "user" ]; then
echo "$v"
break
fi
done < "$config"
fi
}
# __hub_github_repos [FORMAT]
# List all github hosted repository
# FORMAT - Format string contains multiple of these:
# \m remote
# \p owner/repo
# \o owner
# escaped characters (\n, \t ...etc) work
# If omitted, prints all github repos in the format of "remote:owner/repo"
__hub_github_repos() {
local f format=$1
if [ -z "$(__gitdir)" ]; then
return
fi
if [ -z "$format" ]; then
format='\1:\2'
else
format=${format//\m/\1}
format=${format//\p/\2}
format=${format//\o/\3}
fi
command git config --get-regexp 'remote\.[^.]*\.url' |
grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#'
}
# __hub_heads
# List all local "branch", and remote "owner/repo:branch"
__hub_heads() {
local i remote repo branch dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/heads/"
for i in $(__hub_github_repos); do
remote=${i%%:*}
repo=${i#*:}
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read branch; do
echo "${repo}:${branch#${remote}/}"
done
done
fi
}
# __hub_revlist [REMOTE]
# List all tags, and branches under REMOTE, without the "remote/" prefix
# REMOTE - Remote name to search branches from. Default is "origin"
__hub_revlist() {
local i remote=${1:-origin} dir=$(__gitdir)
if [ -d "$dir" ]; then
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/remotes/${remote}/" | while read i; do
echo "${i#${remote}/}"
done
command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
"refs/tags/"
fi
}
# Enable completion for hub even when not using the alias
complete -o bashdefault -o default -o nospace -F _git hub 2>/dev/null \
|| complete -o default -o nospace -F _git hub
fi

@ -0,0 +1,141 @@
# Completions for JBoss Application Server 7 (EAP 6)
# VERSION: 0.6
# DATE: 2012-10-30
# rparree-at-edc4it-dot-com
_serverProfiles(){
if [[ $COMP_WORDS == *standalone.sh* ]]
then
serverdir="../standalone/configuration/"
else
# assume is domain.sh
serverdir="../domain/configuration/"
fi
for i in ${!COMP_WORDS[*]}
do
if [[ "${COMP_WORDS[i]}" == "-Djboss.server.base.dir" || "${COMP_WORDS[i]}" == "-Djboss.domain.base.dir" ]]; then
serverdir="${COMP_WORDS[i+2]}/configuration"
fi
done
if [ -d "${serverdir}" ]
then
IFS=$'\n' tmp="$(ls "${serverdir}" | grep xml)"
local fls="${tmp[@]// /\ }"
unset IFS
COMPREPLY=( $(compgen -W "${fls} initial boot last v" -- "$cur" ))
fi
}
_bindingAddress(){
# from /etc/bash_completion.d/ssh
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W \
"0.0.0.0 $( PATH="$PATH:/sbin" ifconfig -a | \
sed -ne 's/.*addr:\([^[:space:]]*\).*/\1/p' \
-ne 's/.*inet[[:space:]]\{1,\}\([^[:space:]]*\).*/\1/p' )" \
-- "$cur" ) )
}
_jboss(){
local cur prev words cword
COMPREPLY=()
_get_comp_words_by_ref -n = cur prev words cword
case $cur in
-Djboss.socket.binding.port-offset=*)
cur=${cur#*=}
#static list of common bindings sets
local bindings="100 200 300 400 10000 20000 30000 40000"
COMPREPLY=( $(compgen -W "${bindings}" -- ${cur}) )
return 0
;;
-Djboss.default.jgroups.stack=*)
cur=${cur#*=}
#static list of standard JGroups stacks
local stacks="udp udp-async udp-sync tcp tcp-sync"
COMPREPLY=( $(compgen -W "${stacks}" -- ${cur}) )
return 0
;;
-Dorg.jboss.ejb3.remoting.IsLocalInterceptor.passByRef=*|-Dcom.sun.management.jmxremote.authenticate=*|-Dcom.sun.management.jmxremote.ssl=*)
cur=${cur#*=}
local booleans="true false"
COMPREPLY=( $(compgen -W "${booleans}" -- ${cur}) )
return 0
;;
-Djboss.server.base.dir=*|-Djboss.home.dir=*|-Djboss.domain.base.dir=*)
cur=${cur#*=}
_filedir -d
return 0
;;
-Djboss.domain.master.address=*|-Djboss.bind.address*=*)
cur=${cur#*=}
_bindingAddress
return 0
;;
--server-config=*|-c=|--host-config=*)
cur=${cur#*=}
_serverProfiles
return 0
esac
case $prev in
-u)
# a few from RFC 2365 IPv4 Local Scope ()
local addresses="239.255.0.1 239.255.0.2 239.255.0.3"
COMPREPLY=( $(compgen -W "${addresses}" -- ${cur}) )
return 0
;;
-b*)
_bindingAddress
return 0
;;
-c)
_serverProfiles
return 0
;;
*)
;;
esac
# *** from jboss5 ********************
# *** -modulepath -c -m -g -l -d -p -n -B -L -C -Djboss.platform.mbeanserver -Djboss.server.base.directory
# *** -Djboss.Domain -Djboss.modcluster.proxyList -Djboss.jvmRoute -Djboss.default.jgroups.stack -Dorg.jboss.ejb3.remoting.IsLocalInterceptor.passByRef -Djboss.platform.mbeanserver -Dcom.sun.management.jmxremote.port -Dcom.sun.management.jmxremote.ssl
# *************************************
# standard commands for standalone and domain mode
local commandsWithoutEqualSign='-b -bmanagement -bunsecure -bpublic --admin-only -h -help -u -version -V -v'
local commandsWithEqualSign='-P -Djboss.node.name -Djboss.home.dir -Djboss.socket.binding.port-offset -Djboss.bind.address.management -Djboss.bind.address -Djboss.bind.address.unsecure'
if [[ $COMP_WORDS == *standalone.sh* ]]
then
commandsWithoutEqualSign="${commandsWithoutEqualSign} -c"
commandsWithEqualSign="${commandsWithEqualSign} --server-config -Djboss.server.base.dir -c"
else
# assume is domain.sh
commandsWithoutEqualSign="${commandsWithoutEqualSign} --backup --cached-dc"
commandsWithEqualSign="${commandsWithEqualSign} -Djboss.domain.master.address --host-config -Djboss.domain.master.port -Djboss.domain.base.dir "
fi
COMPREPLY=( $( compgen -W "$commandsWithoutEqualSign" -- "$cur" )
$( compgen -W "$commandsWithEqualSign" -S '=' -- "$cur" ) )
return 0
}
complete -o nospace -F _jboss standalone.sh
complete -o nospace -F _jboss domain.sh

@ -0,0 +1 @@
[[ -x "$(which jungle)" ]] && eval "$(_JUNGLE_COMPLETE=source jungle)"

@ -0,0 +1 @@
which kontena > /dev/null && . "$( kontena whoami --bash-completion-path )"

@ -0,0 +1,8 @@
#!/usr/bin/env bash
# kubectl (Kubernetes CLI) completion
if command -v kubectl &>/dev/null
then
eval "$(kubectl completion bash)"
fi

@ -0,0 +1,3 @@
# Add completion for Makefile
# see http://stackoverflow.com/a/38415982/1472048
complete -W "\`grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' Makefile | sed 's/[^a-zA-Z0-9_-]*$//'\`" make

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Bash Maven completion
_mvn()
{
local cmds cur colonprefixes
cmds="clean validate compile test package integration-test \
verify install deploy test-compile site generate-sources \
process-sources generate-resources process-resources \
eclipse:eclipse eclipse:add-maven-repo eclipse:clean \
idea:idea -DartifactId= -DgroupId= -Dmaven.test.skip=true \
-Declipse.workspace= -DarchetypeArtifactId= \
netbeans-freeform:generate-netbeans-project \
tomcat:run tomcat:run-war tomcat:deploy jboss-as:deploy \
versions:display-dependency-updates \
versions:display-plugin-updates dependency:analyze \
dependency:analyze-dep-mgt dependency:resolve \
dependency:sources dependency:tree release:prepare \
release:rollback release:perform --batch-mode"
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# Work-around bash_completion issue where bash interprets a colon
# as a separator.
# Work-around borrowed from the darcs work-around for the same
# issue.
colonprefixes=${cur%"${cur##*:}"}
COMPREPLY=( $(compgen -W '$cmds' -- $cur))
local i=${#COMPREPLY[*]}
while [ $((--i)) -ge 0 ]; do
COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}
done
return 0
} &&
complete -F _mvn mvn

@ -0,0 +1,9 @@
#!/usr/bin/env bash
# npm (Node Package Manager) completion
# https://docs.npmjs.com/cli/completion
if command -v npm &>/dev/null
then
eval "$(npm completion)"
fi

@ -0,0 +1,8 @@
#!/usr/bin/env bash
# nvm (Node Version Manager) completion
if [ "$NVM_DIR" ] && [ -r "$NVM_DIR"/bash_completion ];
then
. "$NVM_DIR"/bash_completion
fi

@ -0,0 +1,164 @@
#!/usr/bin/env bash
# Packer (http://www.packer.io) bash completion
#
# This script provides bash completion for packer and supports:
#
# - template filename completion (*.json) in cwd
# - support for basic options (i.e.. -debug)
# - support for complex options (i.e. -parallel=[true|false]
#
# The scirpt has been successfully tested with packer-0.6.0 and the
# following OS:
#
# - OS X 10.9
# - CentOS-6.5
# - Ubuntu 12.04 Server
#
# The script technically is heavily inspired by the git-completion.bash
# script. Kudos to Shawn O. Pearce <spearce@spearce.org> and all other
# contributors for the inspiration and especially to the bash-completion
# team in general.
#
# Copyright (c) 2014 IT Services Department, University of Bern
#
# This script is licensed under the MIT License (MIT)
# For licsense details see the LICENSE file included in the repository
# or read the license text at http://opensource.org/licenses/MIT.
#
# Generates completion reply, appending a space to possible completion words,
# if necessary.
# It accepts 2 arguments though the second is optional:
# 1: List of possible completion words.
# 2: Generate possible completion matches for this word (optional).
__packercomp ()
{
local cur_="${2-$cur}"
case "$cur_" in
-*=)
;;
*)
local c i=0 IFS=$' \t\n'
for c in $1; do
if [[ $c == "$cur_"* ]]; then
case $c in
-*=*|*.) ;;
*) c="$c " ;;
esac
COMPREPLY[i++]="$c"
fi
done
;;
esac
}
# Generates completion reply for template files in cwd.
__packercomp_template_file ()
{
local IFS=$'\n'
COMPREPLY=($(compgen -S " " -A file -X '!*.json' -- "${cur}"))
}
# Generates completion for the build command.
__packer_build ()
{
local builders="
amazon-ebs amazon-instance amazon-chroot digitalocean docker
googlecompute openstack parallels-iso parallels-pvm qemu
virtualbox-iso virtualbox-ovf vmware-iso vmware-vmx"
case "$cur" in
-parallel=*)
__packercomp "false true" "${cur##-parallel=}"
return
;;
-except=*)
__packercomp "$builders" "${cur##-except=}"
return
;;
-only=*)
__packercomp "$builders" "${cur##-only=}"
return
;;
-*)
__packercomp "-debug -force -machine-readable -except= -only= -parallel= -var -var-file"
return
;;
*)
esac
__packercomp_template_file
}
# Generates completion for the fix command.
__packer_fix ()
{
__packercomp_template_file
}
# Generates completion for the inspect command.
__packer_inspect ()
{
case "$cur" in
-*)
__packercomp "-machine-readable"
return
;;
*)
esac
__packercomp_template_file
}
# Generates completion for the validate command.
__packer_validate ()
{
__packercomp_template_file
}
# Main function for packer completion.
#
# Searches for a command in $COMP_WORDS. If one is found
# the appropriate function from above is called, if not
# completion for global options is done.
_packer_completion ()
{
cur=${COMP_WORDS[COMP_CWORD]}
# Words containing an equal sign get split into tokens in bash > 4, which
# doesn't come in handy here.
# This is handled here. bash < 4 does not split.
declare -f _get_comp_words_by_ref >/dev/null && _get_comp_words_by_ref -n = cur
COMPREPLY=()
local i c=1 command
while [ $c -lt $COMP_CWORD ]; do
i="${COMP_WORDS[c]}"
case "$i" in
-*) ;;
*) command="$i"; break ;;
esac
((c++))
done
if [ -z $command ]; then
case "$cur" in
'-'*)
__packercomp "-machine-readable --help --version"
;;
*)
__packercomp "build fix inspect validate"
;;
esac
return
fi
local completion_func="__packer_${command}"
declare -f $completion_func >/dev/null && $completion_func
}
complete -o nospace -F _packer_completion packer

@ -0,0 +1,11 @@
# pip bash completion start
_pip_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
PIP_AUTO_COMPLETE=1 $1 ) )
}
complete -o default -F _pip_completion pip
# pip bash completion end

@ -0,0 +1,11 @@
# pip bash completion start
_pip_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
PIP_AUTO_COMPLETE=1 $1 ) )
}
complete -o default -F _pip_completion pip3
# pip bash completion end

@ -0,0 +1,39 @@
_pj() {
[ -z "$PROJECT_PATHS" ] && return
shift
[ "$1" == "open" ] && shift
local cur prev words cword
_init_completion || return
local IFS=$'\n' i j k
compopt -o filenames
local -r mark_dirs=$(_rl_enabled mark-directories && echo y)
local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y)
for i in ${PROJECT_PATHS//:/$'\n'}; do
# create an array of matched subdirs
k="${#COMPREPLY[@]}"
for j in $( compgen -d $i/$cur ); do
if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
j+="/"
fi
COMPREPLY[k++]=${j#$i/}
done
done
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
i=${COMPREPLY[0]}
if [[ "$i" == "$cur" && $i != "*/" ]]; then
COMPREPLY[0]="${i}/"
fi
fi
return 0
}
complete -F _pj -o nospace pj
complete -F _pj -o nospace pjo

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Bash completion support for Rake, Ruby Make.
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
_rakecomplete() {
if [ -f Rakefile ]; then
recent=`ls -t .rake_tasks~ Rakefile **/*.rake 2> /dev/null | head -n 1`
if [[ $recent != '.rake_tasks~' ]]; then
rake --silent --tasks | cut -d " " -f 2 > .rake_tasks~
fi
COMPREPLY=($(compgen -W "`cat .rake_tasks~`" -- ${COMP_WORDS[COMP_CWORD]}))
return 0
fi
}
complete -o default -o nospace -F _rakecomplete rake

@ -0,0 +1,329 @@
# written by David Pravec
# - feel free to /msg alekibango on IRC if you want to talk about this file
# TODO: check if --config|-c was used and use configured config file for queries
# TODO: solve somehow completion for salt -G pythonversion:[tab]
# (not sure what to do with lists)
# TODO: --range[tab] -- how?
# TODO: --compound[tab] -- how?
# TODO: use history to extract some words, esp. if ${cur} is empty
# TODO: TEST EVERYTHING a lot
# TODO: cache results of some functions? where? how long?
# TODO: is it ok to use '--timeout 2' ?
_salt_get_grains(){
if [ "$1" = 'local' ] ; then
salt-call --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g'
else
salt '*' --timeout 2 --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g'
fi
}
_salt_get_grain_values(){
if [ "$1" = 'local' ] ; then
salt-call --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$'
else
salt '*' --timeout 2 --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$'
fi
}
_salt(){
local cur prev opts _salt_grains _salt_coms pprev ppprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ ${COMP_CWORD} -gt 2 ]; then
pprev="${COMP_WORDS[COMP_CWORD-2]}"
fi
if [ ${COMP_CWORD} -gt 3 ]; then
ppprev="${COMP_WORDS[COMP_CWORD-3]}"
fi
opts="-h --help -d --doc --documentation --version --versions-report -c \
--config-dir= -v --verbose -t --timeout= -s --static -b --batch= \
--batch-size= -E --pcre -L --list -G --grain --grain-pcre -N \
--nodegroup -R --range -C --compound -I --pillar \
--return= -a --auth= --eauth= --extended-auth= -T --make-token -S \
--ipcidr --out=pprint --out=yaml --out=overstatestage --out=json \
--out=raw --out=highstate --out=key --out=txt --no-color --out-indent= "
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
fi
# 2 special cases for filling up grain values
case "${pprev}" in
-G|--grain|--grain-pcre)
if [ "${cur}" = ":" ]; then
COMPREPLY=($(compgen -W "`_salt_get_grain_values ${prev}`" ))
return 0
fi
;;
esac
case "${ppprev}" in
-G|--grain|--grain-pcre)
if [ "${prev}" = ":" ]; then
COMPREPLY=( $(compgen -W "`_salt_get_grain_values ${pprev}`" -- ${cur}) )
return 0
fi
;;
esac
if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then
prev="${pprev}"
fi
case "${prev}" in
-c|--config)
COMPREPLY=($(compgen -f -- ${cur}))
return 0
;;
salt)
COMPREPLY=($(compgen -W "\'*\' ${opts} `salt-key --no-color -l acc`" -- ${cur}))
return 0
;;
-E|--pcre)
COMPREPLY=($(compgen -W "`salt-key --no-color -l acc`" -- ${cur}))
return 0
;;
-G|--grain|--grain-pcre)
COMPREPLY=($(compgen -W "$(_salt_get_grains)" -- ${cur}))
return 0
;;
-C|--compound)
COMPREPLY=() # TODO: finish this one? how?
return 0
;;
-t|--timeout)
COMPREPLY=($( compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 60 90 120 180" -- ${cur}))
return 0
;;
-b|--batch|--batch-size)
COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 50 60 70 80 90 100 120 150 200"))
return 0
;;
-N|--nodegroup)
MASTER_CONFIG='/etc/salt/master'
COMPREPLY=($(compgen -W "`awk -F ':' 'BEGIN {print_line = 0}; /^nodegroups/ {print_line = 1;getline } print_line && /^ */ {print $1} /^[^ ]/ {print_line = 0}' <${MASTER_CONFIG}`" -- ${cur}))
return 0
;;
esac
_salt_coms="$(salt '*' --timeout 2 --out=txt -- sys.list_functions | sed 's/^.*\[//' | tr -d ",']" )"
all="${opts} ${_salt_coms}"
COMPREPLY=( $(compgen -W "${all}" -- ${cur}) )
return 0
}
complete -F _salt salt
_saltkey(){
local cur prev opts prev pprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-c --config-dir= -h --help --version --versions-report -q --quiet \
-y --yes --gen-keys= --gen-keys-dir= --keysize= --key-logfile= \
-l --list= -L --list-all -a --accept= -A --accept-all \
-r --reject= -R --reject-all -p --print= -P --print-all \
-d --delete= -D --delete-all -f --finger= -F --finger-all \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if [ ${COMP_CWORD} -gt 2 ]; then
pprev="${COMP_WORDS[COMP_CWORD-2]}"
fi
if [ ${COMP_CWORD} -gt 3 ]; then
ppprev="${COMP_WORDS[COMP_CWORD-3]}"
fi
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
fi
if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then
prev="${pprev}"
fi
case "${prev}" in
-a|--accept)
COMPREPLY=($(compgen -W "$(salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur}))
return 0
;;
-r|--reject)
COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color)" -- ${cur}))
return 0
;;
-d|--delete)
COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur}))
return 0
;;
-c|--config)
COMPREPLY=($(compgen -f -- ${cur}))
return 0
;;
--keysize)
COMPREPLY=($(compgen -W "2048 3072 4096 5120 6144" -- ${cur}))
return 0
;;
--gen-keys)
return 0
;;
--gen-keys-dir)
COMPREPLY=($(compgen -d -- ${cur}))
return 0
;;
-p|--print)
COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur}))
return 0
;;
-l|--list)
COMPREPLY=($(compgen -W "pre un acc accepted unaccepted rej rejected all" -- ${cur}))
return 0
;;
--accept-all)
return 0
;;
esac
COMPREPLY=($(compgen -W "${opts} " -- ${cur}))
return 0
}
complete -F _saltkey salt-key
_saltcall(){
local cur prev opts _salt_coms pprev ppprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-h --help -d --doc --documentation --version --versions-report \
-m --module-dirs= -g --grains --return= --local -c --config-dir= -l --log-level= \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if [ ${COMP_CWORD} -gt 2 ]; then
pprev="${COMP_WORDS[COMP_CWORD-2]}"
fi
if [ ${COMP_CWORD} -gt 3 ]; then
ppprev="${COMP_WORDS[COMP_CWORD-3]}"
fi
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
fi
if [ "${cur}" = "=" ] && [[ ${prev} == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ ${pprev} == --* ]]; then
prev="${pprev}"
fi
case ${prev} in
-m|--module-dirs)
COMPREPLY=( $(compgen -d ${cur} ))
return 0
;;
-l|--log-level)
COMPREPLY=( $(compgen -W "info none garbage trace warning error debug" -- ${cur}))
return 0
;;
-g|grains)
return 0
;;
salt-call)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
_salt_coms="$(salt-call --out=txt -- sys.list_functions|sed 's/^.*\[//' | tr -d ",']" )"
COMPREPLY=( $(compgen -W "${opts} ${_salt_coms}" -- ${cur} ))
return 0
}
complete -F _saltcall salt-call
_saltcp(){
local cur prev opts target prefpart postpart helper filt pprev ppprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-t --timeout= -s --static -b --batch= --batch-size= \
-h --help --version --versions-report -c --config-dir= \
-E --pcre -L --list -G --grain --grain-pcre -N --nodegroup \
-R --range -C --compound -I --pillar \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
fi
if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then
prev=${pprev}
fi
case ${prev} in
salt-cp)
COMPREPLY=($(compgen -W "${opts} `salt-key -l acc --no-color`" -- ${cur}))
return 0
;;
-t|--timeout)
# those numbers are just a hint
COMPREPLY=($(compgen -W "2 3 4 8 10 15 20 25 30 40 60 90 120 180 240 300" -- ${cur} ))
return 0
;;
-E|--pcre)
COMPREPLY=($(compgen -W "`salt-key -l acc --no-color`" -- ${cur}))
return 0
;;
-L|--list)
# IMPROVEMENTS ARE WELCOME
prefpart="${cur%,*},"
postpart=${cur##*,}
filt="^\($(echo ${cur}| sed 's:,:\\|:g')\)$"
helper=($(salt-key -l acc --no-color | grep -v "${filt}" | sed "s/^/${prefpart}/"))
COMPREPLY=($(compgen -W "${helper[*]}" -- ${cur}))
return 0
;;
-G|--grain|--grain-pcre)
COMPREPLY=($(compgen -W "$(_salt_get_grains)" -- ${cur}))
return 0
;;
# FIXME
-R|--range)
# FIXME ??
return 0
;;
-C|--compound)
# FIXME ??
return 0
;;
-c|--config)
COMPREPLY=($(compgen -f -- ${cur}))
return 0
;;
esac
# default is using opts:
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _saltcp salt-cp

@ -0,0 +1,61 @@
_sdkman_complete()
{
local CANDIDATES
local CANDIDATE_VERSIONS
COMPREPLY=()
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -W "install uninstall rm list ls use current outdated version default selfupdate broadcast offline help flush" -- ${COMP_WORDS[COMP_CWORD]}) )
elif [ $COMP_CWORD -eq 2 ]; then
case "${COMP_WORDS[COMP_CWORD-1]}" in
"install" | "uninstall" | "rm" | "list" | "ls" | "use" | "current" | "outdated" )
CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ')
COMPREPLY=( $(compgen -W "$CANDIDATES" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
"offline" )
COMPREPLY=( $(compgen -W "enable disable" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
"selfupdate" )
COMPREPLY=( $(compgen -W "force" -P "[" -S "]" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
"flush" )
COMPREPLY=( $(compgen -W "candidates broadcast archives temp" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
*)
;;
esac
elif [ $COMP_CWORD -eq 3 ]; then
case "${COMP_WORDS[COMP_CWORD-2]}" in
"install" | "uninstall" | "rm" | "use" | "default" )
_sdkman_candidate_versions ${COMP_WORDS[COMP_CWORD-1]}
COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) )
;;
*)
;;
esac
fi
return 0
}
_sdkman_candidate_versions(){
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions $1)
if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then
CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS
else
CANDIDATE_ONLINE_VERSIONS="$(curl -s "${SDKMAN_SERVICE}/candidates/$1" | tr ',' ' ')"
CANDIDATE_VERSIONS="$(echo $CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS |sort | uniq ) "
fi
}
__sdkman_cleanup_local_versions(){
__sdkman_build_version_csv $1
echo $CSV | tr ',' ' '
}
complete -F _sdkman_complete sdk

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Bash completion support for ssh.
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
_sshcomplete() {
local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}"
if [[ ${CURRENT_PROMPT} == *@* ]] ; then
local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}"
else
local OPTIONS=" -- ${CURRENT_PROMPT}"
fi
# parse all defined hosts from .ssh/config
if [ -r "$HOME/.ssh/config" ]; then
COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
fi
# parse all hosts found in .ssh/known_hosts
if [ -r "$HOME/.ssh/known_hosts" ]; then
if grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts" ; then
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS}) )
fi
fi
# parse hosts defined in /etc/hosts
if [ -r /etc/hosts ]; then
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
fi
return 0
}
complete -o default -o nospace -F _sshcomplete ssh scp

1514
completion/svn.completion.sh Normal file

File diff suppressed because it is too large Load Diff

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Loads the system's Bash completion modules.
# If Homebrew is installed (OS X), its Bash completion modules are loaded.
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# Some distribution makes use of a profile.d script to import completion.
if [ -f /etc/profile.d/bash_completion.sh ]; then
. /etc/profile.d/bash_completion.sh
fi
if [ $(uname) = "Darwin" ] && command -v brew &>/dev/null ; then
BREW_PREFIX=$(brew --prefix)
if [ -f "$BREW_PREFIX"/etc/bash_completion ]; then
. "$BREW_PREFIX"/etc/bash_completion
fi
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
if [ -f "$BREW_PREFIX"/share/bash-completion/bash_completion ]; then
. "$BREW_PREFIX"/share/bash-completion/bash_completion
fi
fi

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Bash Terraform completion
_terraform()
{
local cmds cur colonprefixes
cmds="apply destroy fmt get graph import init \
output plan push refresh remote show taint \
untaint validate version state"
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# Work-around bash_completion issue where bash interprets a colon
# as a separator.
# Work-around borrowed from the darcs work-around for the same
# issue.
colonprefixes=${cur%"${cur##*:}"}
COMPREPLY=( $(compgen -W '$cmds' -- $cur))
local i=${#COMPREPLY[*]}
while [ $((--i)) -ge 0 ]; do
COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}
done
return 0
} &&
complete -F _terraform terraform

@ -0,0 +1,31 @@
__kitchen_instance_list () {
# cache to .kitchen.list.yml
if [[ .kitchen.yml -nt .kitchen.list.yml || .kitchen.local.yml -nt .kitchen.list.yml ]]; then
# update list if config has updated
kitchen list --bare > .kitchen.list.yml
fi
cat .kitchen.list.yml
}
__kitchen_options () {
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=()
case $prev in
converge|create|destroy|diagnose|list|login|setup|test|verify)
COMPREPLY=( $(compgen -W "$(__kitchen_instance_list)" -- ${cur} ))
return 0
;;
driver)
COMPREPLY=( $(compgen -W "create discover help" -- ${cur} ))
return 0
;;
*)
COMPREPLY=( $(compgen -W "console converge create destroy driver help init list login setup test verify version" -- ${cur} ))
return 0
;;
esac
}
complete -F __kitchen_options kitchen

@ -0,0 +1,188 @@
#!/usr/bin/env bash
# tmux completion
# See: http://www.debian-administration.org/articles/317 for how to write more.
# Usage: Put "source bash_completion_tmux.sh" into your .bashrc
# Based upon the example at http://paste-it.appspot.com/Pj4mLycDE
_tmux_expand ()
{
[ "$cur" != "${cur%\\}" ] && cur="$cur"'\';
if [[ "$cur" == \~*/* ]]; then
eval cur=$cur;
else
if [[ "$cur" == \~* ]]; then
cur=${cur#\~};
COMPREPLY=($( compgen -P '~' -u $cur ));
return ${#COMPREPLY[@]};
fi;
fi
}
_tmux_filedir ()
{
local IFS='
';
_tmux_expand || return 0;
if [ "$1" = -d ]; then
COMPREPLY=(${COMPREPLY[@]} $( compgen -d -- $cur ));
return 0;
fi;
COMPREPLY=(${COMPREPLY[@]} $( eval compgen -f -- \"$cur\" ))
}
function _tmux_complete_client() {
local IFS=$'\n'
local cur="${1}"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
}
function _tmux_complete_session() {
local IFS=$'\n'
local cur="${1}"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
}
function _tmux_complete_window() {
local IFS=$'\n'
local cur="${1}"
local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)"
local sessions
sessions="$(tmux -q list-sessions 2>/dev/null | sed -re 's/([^:]+:).*$/\1/')"
if [[ -n "${session_name}" ]]; then
sessions="${sessions}
$(tmux -q list-windows -t "${session_name}" 2>/dev/null | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')"
fi
cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')"
sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${sessions}" -- "${cur}") )
}
_tmux() {
local cur prev
local i cmd cmd_index option option_index
local opts=""
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ ${prev} == -f ]; then
_tmux_filedir
else
# Search for the command
local skip_next=0
for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${skip_next} -eq 1 ]]; then
#echo "Skipping"
skip_next=0;
elif [[ ${COMP_WORDS[i]} != -* ]]; then
cmd="${COMP_WORDS[i]}"
cmd_index=${i}
break
elif [[ ${COMP_WORDS[i]} == -f ]]; then
skip_next=1
fi
done
# Search for the last option command
skip_next=0
for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${skip_next} -eq 1 ]]; then
#echo "Skipping"
skip_next=0;
elif [[ ${COMP_WORDS[i]} == -* ]]; then
option="${COMP_WORDS[i]}"
option_index=${i}
if [[ ${COMP_WORDS[i]} == -- ]]; then
break;
fi
elif [[ ${COMP_WORDS[i]} == -f ]]; then
skip_next=1
fi
done
if [[ $COMP_CWORD -le $cmd_index ]]; then
# The user has not specified a command yet
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux start-server \; list-commands | cut -d' ' -f1)" -- "${cur}") )
else
case ${cmd} in
attach-session|attach)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t -d" ;;
esac ;;
detach-client|detach)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
lock-client|lockc)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
lock-session|locks)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t -d" ;;
esac ;;
new-session|new)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
-[n|d|s]) options="-d -n -s -t --" ;;
*)
if [[ ${COMP_WORDS[option_index]} == -- ]]; then
_command_offset ${option_index}
else
options="-d -n -s -t --"
fi
;;
esac
;;
refresh-client|refresh)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
rename-session|rename)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t" ;;
esac ;;
source-file|source) _tmux_filedir ;;
has-session|has|kill-session)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t" ;;
esac ;;
suspend-client|suspendc)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
switch-client|switchc)
case "$prev" in
-c) _tmux_complete_client "${cur}" ;;
-t) _tmux_complete_session "${cur}" ;;
*) options="-l -n -p -c -t" ;;
esac ;;
send-keys|send)
case "$option" in
-t) _tmux_complete_window "${cur}" ;;
*) options="-t" ;;
esac ;;
esac # case ${cmd}
fi # command specified
fi # not -f
if [[ -n "${options}" ]]; then
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}") )
fi
return 0
}
complete -F _tmux tmux
# END tmux completion

@ -0,0 +1,70 @@
# link: https://github.com/ginatrapani/todo.txt-cli/blob/master/todo_completion
_todo()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local -r OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x"
local -r COMMANDS="\
add a addto addm append app archive command del \
rm depri dp do help list ls listaddons listall lsa listcon \
lsc listfile lf listpri lsp listproj lsprj move \
mv prepend prep pri p replace report shorthelp"
local -r MOVE_COMMAND_PATTERN='^(move|mv)$'
local _todo_sh=${_todo_sh:-todo.sh}
local completions
if [ $COMP_CWORD -eq 1 ]; then
completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons) $OPTS"
elif [[ $COMP_CWORD -gt 2 && ( \
"${COMP_WORDS[COMP_CWORD-2]}" =~ $MOVE_COMMAND_PATTERN || \
"${COMP_WORDS[COMP_CWORD-3]}" =~ $MOVE_COMMAND_PATTERN ) ]]; then
completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile)
else
case "$prev" in
command)
completions=$COMMANDS;;
help)
completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons)";;
addto|listfile|lf)
completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile);;
-*) completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons) $OPTS";;
*) case "$cur" in
+*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listproj)
COMPREPLY=( $( compgen -W "$completions" -- $cur ))
[ ${#COMPREPLY[@]} -gt 0 ] && return 0
completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listproj)
;;
@*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listcon)
COMPREPLY=( $( compgen -W "$completions" -- $cur ))
[ ${#COMPREPLY[@]} -gt 0 ] && return 0
completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listcon)
;;
*) if [[ "$cur" =~ ^[0-9]+$ ]]; then
local todo=$( \
eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' | \
sed -e 's/^ *[0-9]\{1,\} //' -e 's/^\((.) \)\{0,1\}[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' \
-e 's/^\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \
-e 's/[[:space:]]*$//' \
-e '1q' \
)
[ "$todo" ] && COMPREPLY[0]="$cur # $todo"
return 0
else
return 0
fi
;;
esac
;;
esac
fi
COMPREPLY=( $( compgen -W "$completions" -- $cur ))
return 0
}
complete -F _todo todo.sh
complete -F _todo t

@ -0,0 +1,147 @@
#!/bin/bash
# (The MIT License)
#
# Copyright (c) 2014 Kura
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
__pwdln() {
pwdmod="${PWD}/"
itr=0
until [[ -z "$pwdmod" ]];do
itr=$(($itr+1))
pwdmod="${pwdmod#*/}"
done
echo -n $(($itr-1))
}
__vagrantinvestigate() {
if [ -f "${PWD}/.vagrant" -o -d "${PWD}/.vagrant" ];then
echo "${PWD}/.vagrant"
return 0
else
pwdmod2="${PWD}"
for (( i=2; i<=$(__pwdln); i++ ));do
pwdmod2="${pwdmod2%/*}"
if [ -f "${pwdmod2}/.vagrant" -o -d "${pwdmod2}/.vagrant" ];then
echo "${pwdmod2}/.vagrant"
return 0
fi
done
fi
return 1
}
_vagrant() {
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands="snapshot box connect destroy docker-logs docker-run global-status halt help init list-commands login package plugin provision rdp reload resume rsync rsync-auto share ssh ssh-config status suspend up version"
if [ $COMP_CWORD == 1 ]
then
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
fi
if [ $COMP_CWORD == 2 ]
then
case "$prev" in
"init")
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
"up")
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -d $vagrant_state_file ]]
then
vm_list=$(find $vagrant_state_file/machines -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
fi
local up_commands="--no-provision"
COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur}))
return 0
;;
"ssh"|"provision"|"reload"|"halt"|"suspend"|"resume"|"ssh-config")
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -f $vagrant_state_file ]]
then
running_vm_list=$(grep 'active' $vagrant_state_file | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ')
else
running_vm_list=$(find $vagrant_state_file -type f -name "id" | awk -F"/" '{print $(NF-2)}')
fi
COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur}))
return 0
;;
"box")
box_commands="add help list remove repackage"
COMPREPLY=($(compgen -W "${box_commands}" -- ${cur}))
return 0
;;
"plugin")
plugin_commands="install license list uninstall update"
COMPREPLY=($(compgen -W "${plugin_commands}" -- ${cur}))
return 0
;;
"help")
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
;;
"snapshot")
snapshot_commands="back delete go list take"
COMPREPLY=($(compgen -W "${snapshot_commands}" -- ${cur}))
return 0
;;
*)
;;
esac
fi
if [ $COMP_CWORD == 3 ]
then
action="${COMP_WORDS[COMP_CWORD-2]}"
case "$action" in
"up")
if [ "$prev" == "--no-provision" ]; then
COMPREPLY=($(compgen -W "${vm_list}" -- ${cur}))
return 0
fi
;;
"box")
case "$prev" in
"remove"|"repackage")
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
*)
esac
;;
"snapshot")
if [ "$prev" == "go" ]; then
local snapshot_list=$(vagrant snapshot list | awk '/Name:/ { print $2 }')
COMPREPLY=($(compgen -W "${snapshot_list}" -- ${cur}))
return 0
fi
;;
esac
fi
}
complete -F _vagrant vagrant

@ -0,0 +1,51 @@
# ---------------------------------------------------------------------------
# vault-bash-completion
#
# This adds bash completions for [HashiCorp Vault](https://www.vaultproject.io/)
#
# see https://github.com/iljaweis/vault-bash-completion
# ---------------------------------------------------------------------------
function _vault_mounts() {
(
set -euo pipefail
if ! vault mounts 2> /dev/null | awk 'NR > 1 {print $1}'; then
echo "secret"
fi
)
}
function _vault() {
local VAULT_COMMANDS=$(vault 2>&1 | egrep '^ +' | awk '{print $1}')
local cur
local prev
if [ $COMP_CWORD -gt 0 ]; then
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
fi
local line=${COMP_LINE}
if [[ $prev =~ ^(policies|policy-write|policy-delete) ]]; then
local policies=$(vault policies 2> /dev/null)
COMPREPLY=($(compgen -W "$policies" -- $cur))
elif [ "$(echo $line | wc -w)" -le 2 ]; then
if [[ "$line" =~ ^vault\ (read|write|delete|list)\ $ ]]; then
COMPREPLY=($(compgen -W "$(_vault_mounts)" -- ''))
else
COMPREPLY=($(compgen -W "$VAULT_COMMANDS" -- $cur))
fi
elif [[ "$line" =~ ^vault\ (read|write|delete|list)\ (.*)$ ]]; then
path=${BASH_REMATCH[2]}
if [[ "$path" =~ ^([^ ]+)/([^ /]*)$ ]]; then
list=$(vault list -format=yaml ${BASH_REMATCH[1]} 2> /dev/null | awk '{ print $2 }')
COMPREPLY=($(compgen -W "$list" -P "${BASH_REMATCH[1]}/" -- ${BASH_REMATCH[2]}))
else
COMPREPLY=($(compgen -W "$(_vault_mounts)" -- $path))
fi
fi
}
complete -o default -o nospace -F _vault vault

@ -0,0 +1,222 @@
#!/usr/bin/bash
_vboxmanage_realopts() {
echo $(vboxmanage|grep -i vboxmanage|cut -d' ' -f2|grep '\['|tr -s '[\[\|\]\n' ' ')
echo " "
}
__vboxmanage_startvm() {
RUNNING=$(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"')
TOTAL=$(vboxmanage list vms | cut -d' ' -f1 | tr -d '"')
AVAILABLE=""
for VM in $TOTAL; do
MATCH=0;
for RUN in $RUNNING "x"; do
if [ "$VM" == "$RUN" ]; then
MATCH=1
fi
done
(( $MATCH == 0 )) && AVAILABLE="$AVAILABLE $VM "
done
echo $AVAILABLE
}
__vboxmanage_list() {
INPUT=$(vboxmanage list | tr -s '[\[\]\|\n]' ' ' | cut -d' ' -f4-)
PRUNED=""
if [ "$1" == "long" ]; then
for WORD in $INPUT; do
[ "$WORD" == "-l" ] && continue;
[ "$WORD" == "--long" ] && continue;
PRUNED="$PRUNED $WORD"
done
else
PRUNED=$INPUT
fi
echo $PRUNED
}
__vboxmanage_list_vms() {
VMS=""
if [ "x$1" == "x" ]; then
SEPARATOR=" "
else
SEPARATOR=$1
fi
for VM in $(vboxmanage list vms | cut -d' ' -f1 | tr -d '"'); do
[ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}"
VMS="${VMS}${VM}"
done
echo $VMS
}
__vboxmanage_list_runningvms() {
VMS=""
if [ "$1" == "" ]; then
SEPARATOR=" "
else
SEPARATOR=$1
fi
for VM in $(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"'); do
[ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}"
VMS="${VMS}${VM}"
done
echo $VMS
}
__vboxmanage_controlvm() {
echo "pause resume reset poweroff savestate acpipowerbutton"
echo "acpisleepbutton keyboardputscancode guestmemoryballoon"
echo "gueststatisticsinterval usbattach usbdetach vrde vrdeport"
echo "vrdeproperty vrdevideochannelquality setvideomodehint"
echo "screenshotpng setcredentials teleport plugcpu unplugcpu"
echo "cpuexecutioncap"
# setlinkstate<1-N>
# nic<1-N> null|nat|bridged|intnet|hostonly|generic
# [<devicename>] |
# nictrace<1-N> on|off
# nictracefile<1-N> <filename>
# nicproperty<1-N> name=[value]
# natpf<1-N> [<rulename>],tcp|udp,[<hostip>],
# <hostport>,[<guestip>],<guestport>
# natpf<1-N> delete <rulename>
}
__vboxmanage_default() {
realopts=$(_vboxmanage_realopts)
opts=$realopts$(vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep -v '\[' | sort | uniq)
pruned=""
# echo ""
# echo "DEBUG: cur: $cur, prev: $prev"
# echo "DEBUG: default: |$p1|$p2|$p3|$p4|"
case ${cur} in
-*)
echo $opts
# COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac;
for WORD in $opts; do
MATCH=0
for OPT in ${COMP_WORDS[@]}; do
# opts=$(echo ${opts} | grep -v $OPT);
if [ "$OPT" == "$WORD" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "-v" ] && [ "$WORD" == "--version" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "--version" ] && [ "$WORD" == "-v" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "-q" ] && [ "$WORD" == "--nologo" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "--nologo" ] && [ "$WORD" == "-q" ]; then
MATCH=1
break;
fi
done
(( $MATCH == 1 )) && continue;
pruned="$pruned $WORD"
done
# COMPREPLY=($(compgen -W "${pruned}" -- ${cur}))
echo $pruned
return 0
}
_vboxmanage() {
# vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | sort | uniq
local cur p1 p2 p3 p4 opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# echo "cur: |$cur|"
# echo "prev: |$prev|"
# In case current is complete command
case $cur in
startvm|list|controlvm)
COMPREPLY=($(compgen -W "$cur "))
return 0
;;
esac
case $prev in
-v|--version)
return 0
;;
-l|--long)
opts=$(__vboxmanage_list "long")
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
startvm|list)
opts=$(__vboxmanage_$prev)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
--type)
COMPREPLY=($(compgen -W "gui headless" -- ${cur}))
return 0
;;
gui|headless)
# Done. no more completion possible
return 0
;;
vboxmanage|-q|--nologo)
# echo "Got vboxmanage"
opts=$(__vboxmanage_default)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
controlvm)
opts=$(__vboxmanage_list_vms)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
for VM in $(__vboxmanage_list_vms); do
if [ "$VM" == "$prev" ]; then
pprev=${COMP_WORDS[COMP_CWORD-2]}
# echo "previous: $pprev"
case $pprev in
startvm)
opts="--type"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
controlvm)
opts=$(__vboxmanage_controlvm)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0;
;;
esac
fi
done
# echo "Got to end withoug completion"
}
complete -F _vboxmanage vboxmanage

@ -0,0 +1,2 @@
# Add your own custom alias in the custom/aliases directory. Aliases placed
# here will override ones with the same name in the main alias directory.

@ -0,0 +1,2 @@
# Add your own custom completion in the custom/completion directory. Completions placed
# here will override ones with the same name in the main completion directory.

@ -0,0 +1,2 @@
# Add your own custom themes in the custom/themes directory. Themes placed
# here will override ones with the same name in the main themes directory.

@ -10,12 +10,12 @@ HISTSIZE=10000
SAVEHIST=10000
# Show history
case $HIST_STAMPS in
"mm/dd/yyyy") alias history='fc -fl 1' ;;
"dd.mm.yyyy") alias history='fc -El 1' ;;
"yyyy-mm-dd") alias history='fc -il 1' ;;
*) alias history='fc -l 1' ;;
esac
#case $HIST_STAMPS in
#"mm/dd/yyyy") alias history='fc -fl 1' ;;
#"dd.mm.yyyy") alias history='fc -El 1' ;;
#"yyyy-mm-dd") alias history='fc -il 1' ;;
#*) alias history='fc -l 1' ;;
#esac
#shopt append_history
#shopt extended_history

@ -0,0 +1,37 @@
#!/usr/bin/env bash
# colored ls
export LSCOLORS='Gxfxcxdxdxegedabagacad'
if [[ "$DISABLE_LS_COLORS" != "true" ]]; then
# Find the option for using colors in ls, depending on the version
if [[ "$OSTYPE" == netbsd* ]]; then
# On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors);
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
gls --color -d . &>/dev/null && alias ls='gls --color=tty'
elif [[ "$OSTYPE" == openbsd* ]]; then
# On OpenBSD, "gls" (ls from GNU coreutils) and "colorls" (ls from base,
# with color and multibyte support) are available from ports. "colorls"
# will be installed on purpose and can't be pulled in by installing
# coreutils, so prefer it to "gls".
gls --color -d . &>/dev/null && alias ls='gls --color=tty'
colorls -G -d . &>/dev/null && alias ls='colorls -G'
elif [[ "$OSTYPE" == darwin* ]]; then
# this is a good alias, it works by default just using $LSCOLORS
ls -G . &>/dev/null && alias ls='ls -G'
# only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file)
# otherwise, gls will use the default color scheme which is ugly af
[[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d . &>/dev/null && alias ls='gls --color=tty'
else
# For GNU ls, we use the default ls color theme. They can later be overwritten by themes.
if [[ -z "$LS_COLORS" ]]; then
(( $+commands[dircolors] )) && eval "$(dircolors -b)"
fi
#ls --color -d . &>/dev/null && alias ls='ls --color=tty' || { ls -G . &>/dev/null && alias ls='ls -G' }
# Take advantage of $LS_COLORS for completion as well.
#zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
fi
fi

@ -158,10 +158,10 @@ is_confirmed() {
# fi
#
type_exists() {
if [ "$(type -P "$1")" ]; then
return 0
fi
return 1
if [ "$(type -P "$1")" ]; then
return 0
fi
return 1
}
#
@ -170,10 +170,10 @@ return 1
# Usage: if is_os 'darwin'; then
#
is_os() {
if [[ "${OSTYPE}" == $1* ]]; then
return 0
fi
return 1
if [[ "${OSTYPE}" == $1* ]]; then
return 0
fi
return 1
}
#

@ -65,6 +65,20 @@ for plugin in ${plugins[@]}; do
fi
done
# Load all of the completion & aliases files in ~/.oh-my-bash/{completion,aliases}
# that end in .completion.sh & .aliases.sh
# TIP: Add files you don't want in git to .gitignore
for alias_file in $OSH/aliases/*.sh; do
custom_alias_file="${OSH_CUSTOM}/aliases/${alias_file:t}"
[ -f "${custom_alias_file}" ] && alias_file=${custom_alias_file}
source $alias_file
done
for completion_file in $OSH/completion/*.sh; do
custom_completion_file="${OSH_CUSTOM}/completion/${completion_file:t}"
[ -f "${custom_completion_file}" ] && completion_file=${custom_completion_file}
source $completion_file
done
# Load all of your custom configurations from custom/
for config_file in $OSH_CUSTOM/*.sh; do
if [ -f config_file ]; then
@ -72,23 +86,54 @@ for config_file in $OSH_CUSTOM/*.sh; do
fi
done
unset config_file
# Load all of your custom aliases from custom/
for alias_file in $OSH_CUSTOM/*.sh; do
if [ -f alias_file ]; then
source $alias_file
fi
done
unset alias_file
# Load all of your custom completions from custom/
for completion_file in $OSH_CUSTOM/*.sh; do
if [ -f completion_file ]; then
source $completion_file
fi
done
unset completion_file
# Load colors first so they can be use in base theme
source "${OSH}/themes/colours.theme.sh"
source "${OSH}/themes/base.theme.sh"
# Load the theme
if [ "$OSH_THEME" = "random" ]; then
themes=($OSH/themes/*theme.sh)
themes=($OSH/themes/*/*theme.sh)
N=${#themes[@]}
((N=(RANDOM%N)+1))
((N=(RANDOM%N)))
RANDOM_THEME=${themes[$N]}
source "$RANDOM_THEME"
echo "[oh-my-bash] Random theme '$RANDOM_THEME' loaded..."
else
if [ ! "$OSH_THEME" = "" ]; then
if [ -f "$OSH_CUSTOM/$OSH_THEME.theme.sh" ]; then
source "$OSH_CUSTOM/$OSH_THEME.theme.sh"
elif [ -f "$OSH_CUSTOM/themes/$OSH_THEME.theme.sh" ]; then
source "$OSH_CUSTOM/themes/$OSH_THEME.theme.sh"
if [ -f "$OSH_CUSTOM/$OSH_THEME/$OSH_THEME.theme.sh" ]; then
source "$OSH_CUSTOM/$OSH_THEME/$OSH_THEME.theme.sh"
elif [ -f "$OSH_CUSTOM/themes/$OSH_THEME/$OSH_THEME.theme.sh" ]; then
source "$OSH_CUSTOM/themes/$OSH_THEME/$OSH_THEME.theme.sh"
else
source "$OSH/themes/$OSH_THEME.theme.sh"
source "$OSH/themes/$OSH_THEME/$OSH_THEME.theme.sh"
fi
fi
fi
if [[ $PROMPT ]]; then
export PS1="\["$PROMPT"\]"
fi
if ! type_exists '__git_ps1' ; then
source "$OSH/tools/git-prompt.sh"
fi
# Adding Support for other OSes
PREVIEW="less"
[ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview"
[ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app"

@ -0,0 +1,189 @@
#!/usr/bin/env bash
ac_adapter_connected(){
if _command_exists upower;
then
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'charging\|fully-charged'
return $?
elif _command_exists acpi;
then
acpi -a | grep -q "on-line"
return $?
elif _command_exists pmset;
then
pmset -g batt | grep -q 'AC Power'
return $?
elif _command_exists ioreg;
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
return $?
elif _command_exists WMIC;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2'
return $?
fi
}
ac_adapter_disconnected(){
if _command_exists upower;
then
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'discharging'
return $?
elif _command_exists acpi;
then
acpi -a | grep -q "off-line"
return $?
elif _command_exists pmset;
then
pmset -g batt | grep -q 'Battery Power'
return $?
elif _command_exists ioreg;
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
return $?
elif _command_exists WMIC;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1'
return $?
fi
}
battery_percentage(){
about 'displays battery charge as a percentage of full (100%)'
group 'battery'
if _command_exists upower;
then
local UPOWER_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | tail --bytes 5)
echo ${UPOWER_OUTPUT: : -1}
elif _command_exists acpi;
then
local ACPI_OUTPUT=$(acpi -b)
case $ACPI_OUTPUT in
*" Unknown"*)
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 22 | tail -c 2)
case $PERC_OUTPUT in
*%)
echo "0${PERC_OUTPUT}" | head -c 2
;;
*)
echo ${PERC_OUTPUT}
;;
esac
;;
*" Charging"* | *" Discharging"*)
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
echo ${PERC_OUTPUT}
;;
*" Full"*)
echo '100'
;;
*)
echo '-1'
;;
esac
elif _command_exists pmset;
then
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')
case $PMSET_OUTPUT in
100*)
echo '100'
;;
*)
echo $PMSET_OUTPUT | head -c 2
;;
esac
elif _command_exists ioreg;
then
local IOREG_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: "?")}')
case $IOREG_OUTPUT in
100*)
echo '100'
;;
*)
echo $IOREG_OUTPUT | head -c 2
;;
esac
elif _command_exists WMIC;
then
local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*')
case $WINPC in
100*)
echo '100'
;;
*)
echo $WINPC
;;
esac
else
echo "no"
fi
}
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_PERC=$(battery_percentage)
case $BATTERY_PERC 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
}

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
# Description: This file holds all base BASH functions
#
# Sections:
# 1. Make Terminal Better (remapping defaults and adding functionality)
@ -12,7 +12,9 @@
# 6. System Operations & Information
# 7. Date & Time Management
# 8. Web Development
# 9. Reminders & Notes
# 9. <your_section>
#
# X. Reminders & Notes
#
# ---------------------------------------------------------------------------
@ -20,58 +22,45 @@
# 1. MAKE TERMINAL BETTER
# -----------------------------
alias cp='cp -iv' # Preferred 'cp' implementation
alias mv='mv -iv' # Preferred 'mv' implementation
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation
alias ll='ls -lAFh' # Preferred 'ls' implementation
alias less='less -FSRXc' # Preferred 'less' implementation
alias nano='nano -W -$' # Preferred 'nano' implementation
alias wget='wget -c' # Preferred 'wget' implementation (resume download)
cd() { builtin cd "$@"; ll; } # Always list directory contents upon 'cd'
alias cd..='cd ../' # Go back 1 directory level (for fast typers)
alias ..='cd ../' # Go back 1 directory level
alias ...='cd ../../' # Go back 2 directory levels
alias .3='cd ../../../' # Go back 3 directory levels
alias .4='cd ../../../../' # Go back 4 directory levels
alias .5='cd ../../../../../' # Go back 5 directory levels
alias .6='cd ../../../../../../' # Go back 6 directory levels
alias dud='du -d 1 -h' # Short and human-readable file listing
alias duf='du -sh *' # Short and human-readable directory listing
alias ~="cd ~" # ~: Go Home
alias c='clear' # c: Clear terminal display
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths
alias show_options='shopt' # Show_options: display bash options settings
alias fix_stty='stty sane' # fix_stty: Restore terminal settings when screwed up
alias cic='set completion-ignore-case On' # cic: Make tab-completion case-insensitive
alias h='history | grep $1' # h: Find an executed command in .bash_history
alias src='source ~/.bashrc' # src: Reload .bashrc file
mcd () { mkdir -p "$1" && cd "$1"; } # mcd: Makes new Dir and jumps inside
# lr: Full Recursive Directory Listing
# ------------------------------------------
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less'
# mcd: Makes new Dir and jumps inside
# --------------------------------------------------------------------
mcd () { builtin mkdir -p -- "$*" ; builtin cd -- "$*" ; }
# mans: Search manpage given in agument '1' for term given in argument '2' (case insensitive)
# displays paginated result with colored search terms and two lines surrounding each hit. Example: mans mplayer codec
# displays paginated result with colored search terms and two lines surrounding each hit.
# Example: mans mplayer codec
# --------------------------------------------------------------------
mans () {
man $1 | grep -iC2 --color=always $2 | less
}
mans () { man $1 | grep -iC2 --color=always $2 | less ; }
# showa: to remind yourself of an alias (given some part of it)
# ------------------------------------------------------------
showa () { /usr/bin/grep --color=always -i -a1 $@ ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; }
# quiet: mute output of a command
# ------------------------------------------------------------
quiet () {
$* &> /dev/null &
}
# lsgrep: search through directory contents with grep
# ------------------------------------------------------------
lsgrep () { ls | grep "$*" ; }
# banish-cookies: redirect .adobe and .macromedia files to /dev/null
# ------------------------------------------------------------
banish-cookies ()
{
rm -r ~/.macromedia ~/.adobe
ln -s /dev/null ~/.adobe
ln -s /dev/null ~/.macromedia
}
# -------------------------------
# 2. FILE AND FOLDER MANAGEMENT
# -------------------------------
zipf () { zip -r "$1".zip "$1" ; } # zipf: To create a ZIP archive of a folder
alias numFiles='echo $(ls -1 | wc -l)' # numFiles: Count of non-hidden files in current dir
alias make1mb='truncate -s 1m ./1MB.dat' # make1mb: Creates a file of 1mb size (all zeros)
alias make5mb='truncate -s 5m ./5MB.dat' # make5mb: Creates a file of 5mb size (all zeros)
alias make10mb='truncate -s 10m ./10MB.dat' # make10mb: Creates a file of 10mb size (all zeros)
# extract: Extract most know archives with one command
# ---------------------------------------------------------
@ -96,12 +85,44 @@ alias make10mb='truncate -s 10m ./10MB.dat' # make10mb: Creates a file of 1
fi
}
# buf: back up file with timestamp
# ---------------------------------------------------------
buf () {
local filename=$1
local filetime=$(date +%Y%m%d_%H%M%S)
cp -a "${filename}" "${filename}_${filetime}"
}
# del: move files to hidden folder in tmp, that gets cleared on each reboot
# ---------------------------------------------------------
del() {
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash;
}
# mkiso: creates iso from current dir in the parent dir (unless defined)
# ---------------------------------------------------------
mkiso () {
if type "mkisofs" > /dev/null; then
[ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1
[ -z ${2+x} ] && local destpath=../ || local destpath=$2
[ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3
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
else
echo "mkisofs cmd does not exist, please install cdrtools"
fi
}
# ---------------------------
# 3. SEARCHING
# ---------------------------
alias qfind="find . -name " # qfind: Quickly search for file
ff () { /usr/bin/find . -name "$@" ; } # ff: Find file under the current directory
ffs () { /usr/bin/find . -name "$@"'*' ; } # ffs: Find file whose name starts with a given string
ffe () { /usr/bin/find . -name '*'"$@" ; } # ffe: Find file whose name ends with a given string
@ -119,26 +140,6 @@ ffe () { /usr/bin/find . -name '*'"$@" ; } # ffe: Find file whose name end
# -----------------------------------------------------
findPid () { lsof -t -c "$@" ; }
# memHogsTop, memHogsPs: Find memory hogs
# -----------------------------------------------------
alias memHogsTop='top -l 1 -o rsize | head -20'
alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'
# cpuHogs: Find CPU hogs
# -----------------------------------------------------
alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'
# topForever: Continual 'top' listing (every 10 seconds)
# -----------------------------------------------------
alias topForever='top -l 9999999 -s 10 -o cpu'
# ttop: Recommended 'top' invocation to minimize resources
# ------------------------------------------------------------
# Taken from this macosxhints article
# http://www.macosxhints.com/article.php?story=20060816123853639
# ------------------------------------------------------------
alias ttop="top -R -F -s 10 -o rsize"
# my_ps: List processes owned by my user:
# ------------------------------------------------------------
my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }
@ -148,15 +149,32 @@ ffe () { /usr/bin/find . -name '*'"$@" ; } # ffe: Find file whose name end
# 5. NETWORKING
# ---------------------------
alias myip='curl ifconfig.co' # myip: Public facing IP Address
alias netCons='lsof -i' # netCons: Show all open TCP/IP sockets
alias lsock='sudo /usr/sbin/lsof -i -P' # lsock: Display open sockets
alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP' # lsockU: Display only open UDP sockets
alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP' # lsockT: Display only open TCP sockets
alias ipInfo0='ifconfig getpacket en0' # ipInfo0: Get info on connections for en0
alias ipInfo1='ifconfig getpacket en1' # ipInfo1: Get info on connections for en1
alias openPorts='sudo lsof -i | grep LISTEN' # openPorts: All listening connections
alias showBlocked='sudo ipfw list' # showBlocked: All ipfw rules inc/ blocked IPs
# ips: display all ip addresses for this host
# -------------------------------------------------------------------
ips () {
if command -v ifconfig &>/dev/null
then
ifconfig | awk '/inet /{ print $2 }'
elif command -v ip &>/dev/null
then
ip addr | grep -oP 'inet \K[\d.]+'
else
echo "You don't have ifconfig or ip command installed!"
fi
}
# down4me: checks whether a website is down for you, or everybody
# -------------------------------------------------------------------
down4me () {
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
}
# myip: displays your ip address, as seen by the Internet
# -------------------------------------------------------------------
myip () {
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
}
# ii: display useful host related informaton
# -------------------------------------------------------------------
@ -177,16 +195,6 @@ alias showBlocked='sudo ipfw list' # showBlocked: All ip
# 6. SYSTEMS OPERATIONS & INFORMATION
# ---------------------------------------
alias mountReadWrite='/sbin/mount -uw /' # mountReadWrite: For use when booted into single-user
alias perm='stat --printf "%a %n \n "' # perm: Show permission of target in number
alias 000='chmod 000' # ---------- (no fucking permissions)
alias 640='chmod 640' # -rw-r----- (user: rw, group: r, other: -)
alias 644='chmod 644' # -rw-r--r-- (user: rw, group: r, other: -)
alias 755='chmod 755' # -rwxr-xr-x (user: rwx, group: rx, other: x)
alias 775='chmod 775' # -rwxrwxr-x (user: rwx, group: rwx, other: rx)
alias mx='chmod a+x' # ---x--x--x (user: --x, group: --x, other: --x)
alias ux='chmod u+x' # ---x------ (user: --x, group: -, other: -)
# batch_chmod: Batch chmod for all files & sub-directories in the current one
# -------------------------------------------------------------------
batch_chmod()
@ -199,32 +207,62 @@ alias ux='chmod u+x' # ---x------ (user: --x, group: -, o
echo "$(tput sgr0)"
}
# usage: disk usage per directory, in Mac OS X and Linux
# -------------------------------------------------------------------
usage () {
if [ $(uname) = "Darwin" ]; then
if [ -n "$1" ]; then
du -hd 1 "$1"
else
du -hd 1
fi
# ---------------------------------------
# 7. DATE & TIME MANAGEMENT
# ---------------------------------------
alias bdate="date '+%a, %b %d %Y %T %Z'"
alias cal='cal -3'
alias da='date "+%Y-%m-%d %A %T %Z"'
alias daysleft='echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)."'
alias epochtime='date +%s'
alias mytime='date +%H:%M:%S'
alias secconvert='date -d@1234567890'
alias stamp='date "+%Y%m%d%a%H%M"'
alias timestamp='date "+%Y%m%dT%H%M%S"'
alias today='date +"%A, %B %-d, %Y"'
alias weeknum='date +%V'
elif [ $(uname) = "Linux" ]; then
if [ -n "$1" ]; then
du -h --max-depth=1 "$1"
else
du -h --max-depth=1
fi
fi
}
# command_exists: checks for existence of a command (0 = true, 1 = false)
# -------------------------------------------------------------------
command_exists () {
type "$1" &> /dev/null ;
}
# pickfrom: picks random line from file
# -------------------------------------------------------------------
pickfrom () {
local file=$1
[ -z "$file" ] && reference $FUNCNAME && return
length=$(cat $file | wc -l)
n=$(expr $RANDOM \* $length \/ 32768 + 1)
head -n $n $file | tail -1
}
# passgen: generates random password from dictionary words
# Note default length of generated password is 4, you can pass it to the command
# E.g. passgen 15
# -------------------------------------------------------------------
passgen () {
local i pass length=${1:-4}
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
echo "With spaces (easier to memorize): $pass"
echo "Without (use this as the password): $(echo $pass | tr -d ' ')"
}
# ---------------------------------------
# 7. DATE & TIME MANAGEMENT
# ---------------------------------------
# ---------------------------------------
# 8. WEB DEVELOPMENT
# ---------------------------------------
alias apacheEdit='sudo edit /etc/httpd/httpd.conf' # apacheEdit: Edit httpd.conf
alias apacheRestart='sudo apachectl graceful' # apacheRestart: Restart Apache
alias editHosts='sudo edit /etc/hosts' # editHosts: Edit /etc/hosts file
alias herr='tail /var/log/httpd/error_log' # herr: Tails HTTP error logs
alias apacheLogs="less +F /var/log/apache2/error_log" # Apachelogs: Shows apache error logs
httpHeaders () { /usr/bin/curl -I -L $@ ; } # httpHeaders: Grabs headers from web page
# httpDebug: Download a web page and show info on what took time
@ -232,8 +270,10 @@ httpHeaders () { /usr/bin/curl -I -L $@ ; } # httpHeaders: Grab
httpDebug () { /usr/bin/curl $@ -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\n" ; }
# ---------------------------------------
# 9. REMINDERS & NOTES
# X. REMINDERS & NOTES
# ---------------------------------------
# remove_disk: spin down unneeded disk

@ -6,7 +6,7 @@ export OSH=$HOME/.oh-my-bash
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-bash is loaded.
OSH_THEME="powerline"
OSH_THEME="font"
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

@ -0,0 +1,17 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
# Nicely formatted terminal prompt
function prompt_command(){
export PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ "
}
safe_append_prompt_command prompt_command

42
themes/axin/axin.theme.sh Normal file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Axin Bash Prompt, inspired by theme "Sexy" and "Bobby"
# thanks to them
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
MAGENTA=$(tput setaf 9)
ORANGE=$(tput setaf 172)
GREEN=$(tput setaf 190)
PURPLE=$(tput setaf 141)
WHITE=$(tput setaf 0)
else
MAGENTA=$(tput setaf 5)
ORANGE=$(tput setaf 4)
GREEN=$(tput setaf 2)
PURPLE=$(tput setaf 1)
WHITE=$(tput setaf 7)
fi
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
MAGENTA="\033[1;31m"
ORANGE="\033[1;33m"
GREEN="\033[1;32m"
PURPLE="\033[1;35m"
WHITE="\033[1;37m"
BOLD=""
RESET="\033[m"
fi
function prompt_command() {
PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]@ \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\[$SCM_THEME_PROMPT_PREFIX\]$(clock_prompt) \[$PURPLE\]\$(scm_prompt_info) \n\$ \[$RESET\]"
}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"${white}"}
safe_append_prompt_command prompt_command

@ -0,0 +1,22 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"
function prompt_command() {
#PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} "
#PS1="\n${purple}\h: ${reset_color} ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} "
#PS1="\n${cyan}\h: ${reset_color} ${yellow}\w\n${red}$(scm_char)${red}$(scm_prompt_info) ${green}→${reset_color} "
PS1="\n${cyan}\h: ${reset_color} ${yellow}\w ${green}$(scm_prompt_info)\n${reset_color}"
}
safe_append_prompt_command prompt_command

521
themes/base.theme.sh Normal file

@ -0,0 +1,521 @@
#!/usr/bin/env bash
CLOCK_CHAR_THEME_PROMPT_PREFIX=''
CLOCK_CHAR_THEME_PROMPT_SUFFIX=''
CLOCK_THEME_PROMPT_PREFIX=''
CLOCK_THEME_PROMPT_SUFFIX=''
THEME_PROMPT_HOST='\H'
SCM_CHECK=${SCM_CHECK:=true}
SCM_THEME_PROMPT_DIRTY=' ✗'
SCM_THEME_PROMPT_CLEAN=' ✓'
SCM_THEME_PROMPT_PREFIX=' |'
SCM_THEME_PROMPT_SUFFIX='|'
SCM_THEME_BRANCH_PREFIX=''
SCM_THEME_TAG_PREFIX='tag:'
SCM_THEME_DETACHED_PREFIX='detached:'
SCM_THEME_BRANCH_TRACK_PREFIX=' → '
SCM_THEME_BRANCH_GONE_PREFIX=' ⇢ '
SCM_THEME_CURRENT_USER_PREFFIX=' ☺︎ '
SCM_THEME_CURRENT_USER_SUFFIX=''
SCM_THEME_CHAR_PREFIX=''
SCM_THEME_CHAR_SUFFIX=''
THEME_BATTERY_PERCENTAGE_CHECK=${THEME_BATTERY_PERCENTAGE_CHECK:=true}
SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=true}
SCM_GIT_SHOW_REMOTE_INFO=${SCM_GIT_SHOW_REMOTE_INFO:=auto}
SCM_GIT_IGNORE_UNTRACKED=${SCM_GIT_IGNORE_UNTRACKED:=false}
SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false}
SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false}
SCM_GIT='git'
SCM_GIT_CHAR='±'
SCM_GIT_DETACHED_CHAR='⌿'
SCM_GIT_AHEAD_CHAR="↑"
SCM_GIT_BEHIND_CHAR="↓"
SCM_GIT_UNTRACKED_CHAR="?:"
SCM_GIT_UNSTAGED_CHAR="U:"
SCM_GIT_STAGED_CHAR="S:"
SCM_HG='hg'
SCM_HG_CHAR='☿'
SCM_SVN='svn'
SCM_SVN_CHAR='⑆'
SCM_NONE='NONE'
SCM_NONE_CHAR='○'
RVM_THEME_PROMPT_PREFIX=' |'
RVM_THEME_PROMPT_SUFFIX='|'
THEME_SHOW_USER_HOST=${THEME_SHOW_USER_HOST:=false}
USER_HOST_THEME_PROMPT_PREFIX=''
USER_HOST_THEME_PROMPT_SUFFIX=''
VIRTUALENV_THEME_PROMPT_PREFIX=' |'
VIRTUALENV_THEME_PROMPT_SUFFIX='|'
RBENV_THEME_PROMPT_PREFIX=' |'
RBENV_THEME_PROMPT_SUFFIX='|'
RBFU_THEME_PROMPT_PREFIX=' |'
RBFU_THEME_PROMPT_SUFFIX='|'
function scm {
if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE
elif [[ -f .git/HEAD ]]; then SCM=$SCM_GIT
elif which git &> /dev/null && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT
elif [[ -d .hg ]]; then SCM=$SCM_HG
elif which hg &> /dev/null && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG
elif [[ -d .svn ]]; then SCM=$SCM_SVN
else SCM=$SCM_NONE
fi
}
function scm_prompt_char {
if [[ -z $SCM ]]; then scm; fi
if [[ $SCM == $SCM_GIT ]]; then SCM_CHAR=$SCM_GIT_CHAR
elif [[ $SCM == $SCM_HG ]]; then SCM_CHAR=$SCM_HG_CHAR
elif [[ $SCM == $SCM_SVN ]]; then SCM_CHAR=$SCM_SVN_CHAR
else SCM_CHAR=$SCM_NONE_CHAR
fi
}
function scm_prompt_vars {
scm
scm_prompt_char
SCM_DIRTY=0
SCM_STATE=''
[[ $SCM == $SCM_GIT ]] && git_prompt_vars && return
[[ $SCM == $SCM_HG ]] && hg_prompt_vars && return
[[ $SCM == $SCM_SVN ]] && svn_prompt_vars && return
}
function scm_prompt_info {
scm
scm_prompt_char
scm_prompt_info_common
}
function scm_prompt_char_info {
scm_prompt_char
echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
scm_prompt_info_common
}
function scm_prompt_info_common {
SCM_DIRTY=0
SCM_STATE=''
if [[ ${SCM} == ${SCM_GIT} ]]; then
if [[ ${SCM_GIT_SHOW_MINIMAL_INFO} == true ]]; then
# user requests minimal git status information
git_prompt_minimal_info
else
# more detailed git status
git_prompt_info
fi
return
fi
# TODO: consider adding minimal status information for hg and svn
[[ ${SCM} == ${SCM_HG} ]] && hg_prompt_info && return
[[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return
}
# This is added to address bash shell interpolation vulnerability described
# here: https://github.com/njhartwell/pw3nage
function git_clean_branch {
local unsafe_ref=$(command git symbolic-ref -q HEAD 2> /dev/null)
local stripped_ref=${unsafe_ref##refs/heads/}
local clean_ref=${stripped_ref//[^a-zA-Z0-9\/]/-}
echo $clean_ref
}
function git_prompt_minimal_info {
local ref
local status
local git_status_flags=('--porcelain')
SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
if [[ "$(command git config --get bash-it.hide-status)" != "1" ]]; then
# Get the branch reference
ref=$(git_clean_branch) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref}
# Get the status
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags+='-untracked-files=no'
status=$(command git status ${git_status_flags} 2> /dev/null | tail -n1)
if [[ -n ${status} ]]; then
SCM_DIRTY=1
SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
fi
# Output the git prompt
SCM_PREFIX=${SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${SCM_THEME_PROMPT_SUFFIX}
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
fi
}
function git_status_summary {
awk '
BEGIN {
untracked=0;
unstaged=0;
staged=0;
}
{
if (!after_first && $0 ~ /^##.+/) {
print $0
seen_header = 1
} else if ($0 ~ /^\?\? .+/) {
untracked += 1
} else {
if ($0 ~ /^.[^ ] .+/) {
unstaged += 1
}
if ($0 ~ /^[^ ]. .+/) {
staged += 1
}
}
after_first = 1
}
END {
if (!seen_header) {
print
}
print untracked "\t" unstaged "\t" staged
}'
}
function git_prompt_vars {
local details=''
SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
if [[ "$(git config --get bash-it.hide-status)" != "1" ]]; then
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && local git_status_flags='-uno'
local status_lines=$((git status --porcelain ${git_status_flags} -b 2> /dev/null ||
git status --porcelain ${git_status_flags} 2> /dev/null) | git_status_summary)
local status=$(awk 'NR==1' <<< "$status_lines")
local counts=$(awk 'NR==2' <<< "$status_lines")
IFS=$'\t' read untracked_count unstaged_count staged_count <<< "$counts"
if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then
SCM_DIRTY=1
if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; then
[[ "${staged_count}" -gt 0 ]] && details+=" ${SCM_GIT_STAGED_CHAR}${staged_count}" && SCM_DIRTY=3
[[ "${unstaged_count}" -gt 0 ]] && details+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2
[[ "${untracked_count}" -gt 0 ]] && details+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1
fi
SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
fi
fi
[[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && details+="$(git_user_info)"
SCM_CHANGE=$(git rev-parse --short HEAD 2>/dev/null)
local ref=$(git_clean_branch)
if [[ -n "$ref" ]]; then
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}${ref}"
local tracking_info="$(grep -- "${SCM_BRANCH}\.\.\." <<< "${status}")"
if [[ -n "${tracking_info}" ]]; then
[[ "${tracking_info}" =~ .+\[gone\]$ ]] && local branch_gone="true"
tracking_info=${tracking_info#\#\# ${SCM_BRANCH}...}
tracking_info=${tracking_info% [*}
local remote_name=${tracking_info%%/*}
local remote_branch=${tracking_info#${remote_name}/}
local remote_info=""
local num_remotes=$(git remote | wc -l 2> /dev/null)
[[ "${SCM_BRANCH}" = "${remote_branch}" ]] && local same_branch_name=true
if ([[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]] && [[ "${num_remotes}" -ge 2 ]]) ||
[[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then
remote_info="${remote_name}"
[[ "${same_branch_name}" != "true" ]] && remote_info+="/${remote_branch}"
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="${remote_branch}"
fi
if [[ -n "${remote_info}" ]];then
if [[ "${branch_gone}" = "true" ]]; then
SCM_BRANCH+="${SCM_THEME_BRANCH_GONE_PREFIX}${remote_info}"
else
SCM_BRANCH+="${SCM_THEME_BRANCH_TRACK_PREFIX}${remote_info}"
fi
fi
fi
SCM_GIT_DETACHED="false"
else
local detached_prefix=""
ref=$(git describe --tags --exact-match 2> /dev/null)
if [[ -n "$ref" ]]; then
detached_prefix=${SCM_THEME_TAG_PREFIX}
else
ref=$(git describe --contains --all HEAD 2> /dev/null)
ref=${ref#remotes/}
[[ -z "$ref" ]] && ref=${SCM_CHANGE}
detached_prefix=${SCM_THEME_DETACHED_PREFIX}
fi
SCM_BRANCH=${detached_prefix}${ref}
SCM_GIT_DETACHED="true"
fi
local ahead_re='.+ahead ([0-9]+).+'
local behind_re='.+behind ([0-9]+).+'
[[ "${status}" =~ ${ahead_re} ]] && SCM_BRANCH+=" ${SCM_GIT_AHEAD_CHAR}${BASH_REMATCH[1]}"
[[ "${status}" =~ ${behind_re} ]] && SCM_BRANCH+=" ${SCM_GIT_BEHIND_CHAR}${BASH_REMATCH[1]}"
local stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')"
[[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" {${stash_count}}"
SCM_BRANCH+=${details}
SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
}
function svn_prompt_vars {
if [[ -n $(svn status 2> /dev/null) ]]; then
SCM_DIRTY=1
SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else
SCM_DIRTY=0
SCM_STATE=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi
SCM_PREFIX=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
SCM_BRANCH=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return
SCM_CHANGE=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' )
}
# this functions returns absolute location of .hg directory if one exists
# It starts in the current directory and moves its way up until it hits /.
# If we get to / then no Mercurial repository was found.
# Example:
# - lets say we cd into ~/Projects/Foo/Bar
# - .hg is located in ~/Projects/Foo/.hg
# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo
function get_hg_root {
local CURRENT_DIR=$(pwd)
while [ "$CURRENT_DIR" != "/" ]; do
if [ -d "$CURRENT_DIR/.hg" ]; then
echo "$CURRENT_DIR/.hg"
return
fi
CURRENT_DIR=$(dirname $CURRENT_DIR)
done
}
function hg_prompt_vars {
if [[ -n $(hg status 2> /dev/null) ]]; then
SCM_DIRTY=1
SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else
SCM_DIRTY=0
SCM_STATE=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi
SCM_PREFIX=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
HG_ROOT=$(get_hg_root)
if [ -f "$HG_ROOT/branch" ]; then
# Mercurial holds it's current branch in .hg/branch file
SCM_BRANCH=$(cat "$HG_ROOT/branch")
else
SCM_BRANCH=$(hg summary 2> /dev/null | grep branch: | awk '{print $2}')
fi
if [ -f "$HG_ROOT/dirstate" ]; then
# Mercurial holds various information about the working directory in .hg/dirstate file. More on http://mercurial.selenic.com/wiki/DirState
SCM_CHANGE=$(hexdump -n 10 -e '1/1 "%02x"' "$HG_ROOT/dirstate" | cut -c-12)
else
SCM_CHANGE=$(hg summary 2> /dev/null | grep parent: | awk '{print $2}')
fi
}
function rvm_version_prompt {
if which rvm &> /dev/null; then
rvm=$(rvm-prompt) || return
if [ -n "$rvm" ]; then
echo -e "$RVM_THEME_PROMPT_PREFIX$rvm$RVM_THEME_PROMPT_SUFFIX"
fi
fi
}
function rbenv_version_prompt {
if which rbenv &> /dev/null; then
rbenv=$(rbenv version-name) || return
$(rbenv commands | grep -q gemset) && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}"
if [ $rbenv != "system" ]; then
echo -e "$RBENV_THEME_PROMPT_PREFIX$rbenv$RBENV_THEME_PROMPT_SUFFIX"
fi
fi
}
function rbfu_version_prompt {
if [[ $RBFU_RUBY_VERSION ]]; then
echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}"
fi
}
function chruby_version_prompt {
if declare -f -F chruby &> /dev/null; then
if declare -f -F chruby_auto &> /dev/null; then
chruby_auto
fi
ruby_version=$(ruby --version | awk '{print $1, $2;}') || return
if [[ ! $(chruby | grep '*') ]]; then
ruby_version="${ruby_version} (system)"
fi
echo -e "${CHRUBY_THEME_PROMPT_PREFIX}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX}"
fi
}
function ruby_version_prompt {
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
}
function virtualenv_prompt {
if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=`basename "$VIRTUAL_ENV"`
echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX"
fi
}
function condaenv_prompt {
if [[ $CONDA_DEFAULT_ENV ]]; then
echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}"
fi
}
function py_interp_prompt {
py_version=$(python --version 2>&1 | awk '{print "py-"$2;}') || return
echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}"
}
function python_version_prompt {
echo -e "$(virtualenv_prompt)$(condaenv_prompt)$(py_interp_prompt)"
}
function git_user_info {
# support two or more initials, set by 'git pair' plugin
SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%')
# if `user.initials` weren't set, attempt to extract initials from `user.name`
[[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" $(for word in $(git config user.name | tr 'A-Z' 'a-z'); do printf "%1.1s" $word; done))
[[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX"
}
function clock_char {
CLOCK_CHAR=${THEME_CLOCK_CHAR:-"⌚"}
CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"}
SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"}
if [[ "${SHOW_CLOCK_CHAR}" = "true" ]]; then
echo -e "${CLOCK_CHAR_COLOR}${CLOCK_CHAR_THEME_PROMPT_PREFIX}${CLOCK_CHAR}${CLOCK_CHAR_THEME_PROMPT_SUFFIX}"
fi
}
function clock_prompt {
CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"}
CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"}
[ -z $THEME_SHOW_CLOCK ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"}
SHOW_CLOCK=$THEME_SHOW_CLOCK
if [[ "${SHOW_CLOCK}" = "true" ]]; then
CLOCK_STRING=$(date +"${CLOCK_FORMAT}")
echo -e "${CLOCK_COLOR}${CLOCK_THEME_PROMPT_PREFIX}${CLOCK_STRING}${CLOCK_THEME_PROMPT_SUFFIX}"
fi
}
function user_host_prompt {
if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then
echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}"
fi
}
# backwards-compatibility
function git_prompt_info {
git_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
}
function svn_prompt_info {
svn_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
}
function hg_prompt_info() {
hg_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}"
}
function scm_char {
scm_prompt_char
echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
}
function prompt_char {
scm_char
}
function battery_char {
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
echo -e "${bold_red}$(battery_percentage)%"
fi
}
if ! type_exists 'battery_charge' ; then
# if user has installed battery plugin, skip this...
function battery_charge (){
# no op
echo -n
}
fi
# The battery_char function depends on the presence of the battery_percentage function.
# If battery_percentage is not defined, then define battery_char as a no-op.
if ! type_exists 'battery_percentage' ; then
function battery_char (){
# no op
echo -n
}
fi
function aws_profile {
if [[ $AWS_DEFAULT_PROFILE ]]; then
echo -e "${AWS_DEFAULT_PROFILE}"
else
echo -e "default"
fi
}
function safe_append_prompt_command {
local prompt_re
# Set OS dependent exact match regular expression
if [[ ${OSTYPE} == darwin* ]]; then
# macOS
prompt_re="[[:<:]]${1}[[:>:]]"
else
# Linux, FreeBSD, etc.
prompt_re="\<${1}\>"
fi
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
return
elif [[ -z ${PROMPT_COMMAND} ]]; then
PROMPT_COMMAND="${1}"
else
PROMPT_COMMAND="${1};${PROMPT_COMMAND}"
fi
}

@ -0,0 +1,101 @@
#!/usr/bin/env bash
# Set term to 256color mode, if 256color is not supported, colors won't work properly
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# Detect whether a rebbot is required
function show_reboot_required() {
if [ ! -z "$_bf_prompt_reboot_info" ]; then
if [ -f /var/run/reboot-required ]; then
printf "Reboot required!"
fi
fi
}
# Set different host color for local and remote sessions
function set_host_color() {
# Detect if connection is through SSH
if [[ ! -z $SSH_CLIENT ]]; then
printf "${lime_yellow}"
else
printf "${light_orange}"
fi
}
# Set different username color for users and root
function set_user_color() {
case $(id -u) in
0)
printf "${red}"
;;
*)
printf "${cyan}"
;;
esac
}
scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo "[$(scm_char)$(scm_prompt_info)]"
fi
}
# Define custom colors we need
# non-printable bytes in PS1 need to be contained within \[ \].
# Otherwise, bash will count them in the length of the prompt
function set_custom_colors() {
dark_grey="\[$(tput setaf 8)\]"
light_grey="\[$(tput setaf 248)\]"
light_orange="\[$(tput setaf 172)\]"
bright_yellow="\[$(tput setaf 220)\]"
lime_yellow="\[$(tput setaf 190)\]"
powder_blue="\[$(tput setaf 153)\]"
}
__ps_time() {
echo "$(clock_prompt)${normal}\n"
}
function prompt_command() {
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
ps_username="$(set_user_color)\u${normal}"
ps_uh_separator="${dark_grey}@${normal}"
ps_hostname="$(set_host_color)\h${normal}"
ps_path="${yellow}\w${normal}"
ps_scm_prompt="${light_grey}$(scm_prompt)"
ps_user_mark="${normal} ${normal}"
ps_user_input="${normal}"
# Set prompt
PS1="$ps_reboot$(__ps_time)$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input"
}
# Initialize custom colors
set_custom_colors
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$dark_grey"}
# scm theming
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${light_grey}"
SCM_THEME_PROMPT_CLEAN=" ${green}${light_grey}"
SCM_GIT_CHAR="${green}±${light_grey}"
SCM_SVN_CHAR="${bold_cyan}${light_grey}"
SCM_HG_CHAR="${bold_red}${light_grey}"
safe_append_prompt_command prompt_command

@ -0,0 +1,19 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
CONDAENV_THEME_PROMPT_SUFFIX="|"
function prompt_command() {
#PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} "
PS1="\n${yellow}$(python_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}${reset_color} "
}
safe_append_prompt_command prompt_command

@ -0,0 +1,34 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" ${green}|"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"
__bobby_clock() {
printf "$(clock_prompt) "
if [ "${THEME_SHOW_CLOCK_CHAR}" == "true" ]; then
printf "$(clock_char) "
fi
}
function prompt_command() {
#PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} "
PS1="\n$(battery_char) $(__bobby_clock)${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_prompt_char_info) ${green}${reset_color} "
}
THEME_SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"}
THEME_CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$red"}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$bold_cyan"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%Y-%m-%d %H:%M:%S"}
safe_append_prompt_command prompt_command

123
themes/brainy/README.md Normal file

@ -0,0 +1,123 @@
# Brainy theme
Simple colorful terminal prompt theme (inspired by a number of themes).
## Features
### Prompt Segments
- Username & Hostname
- Current Directory
- SCM Information
- Battery Charge
- Clock
- [Todo.txt](https://github.com/ginatrapani/todo.txt-cli) status
- Ruby Environment
- Python Environment
- Exit Code
### Others
- Indicator for cached `sudo` credential
- Indicator for ssh login
- `brainy` command for showing/hiding various prompt segments on-the-fly
## Configuration
Various prompt segments can be shown/hidden or modified according to your choice. There are two ways for doing that:
1. On-the-fly using `brainy` command
2. Theme Environment Variables
### On-the-fly using `brainy` command
This theme provides a command for showing/hiding prompt segments.
`brainy show <segment>`
`brainy hide <segment>`
Tab-completion for this command is enabled by default.
Configuration specified by this command will only be applied to current and subsequent child shells.
### Theme Environment Variables
This is used for permanent settings that apply to all terminal sessions. You have to define the value of specific theme variables in your `bashrc` (or equivalent) file.
The name of the variables are listed below along with their default values.
#### User Information
Indicator for cached `sudo` credential (see `sudo` manpage for more information):
`THEME_SHOW_SUDO=true`
#### SCM Information
Information about SCM repository status:
`THEME_SHOW_SCM=true`
#### Ruby Environment
Ruby environment version information:
`THEME_SHOW_RUBY=false`
#### Python Environment
Python environment version information:
`THEME_SHOW_PYTHON=false`
#### ToDo.txt status
[Todo.txt](https://github.com/ginatrapani/todo.txt-cli) status:
`THEME_SHOW_TODO=false`
#### Clock
`THEME_SHOW_CLOCK=true`
`THEME_CLOCK_COLOR=$bold_cyan`
Format of the clock (see `date` manpage for more information):
`THEME_CLOCK_FORMAT="%H:%M:%S"`
#### Battery Charge
Battery charge percentage:
`THEME_SHOW_BATTERY=false`
#### Exit Code
Exit code of the last command:
`THEME_SHOW_EXITCODE=true`
## Prompt Segments Order
Currently available prompt segments are:
- battery
- char
- clock
- dir
- exitcode
- python
- ruby
- scm
- todo
- user_info
Three environment variables can be defined to rearrange the segments order. The default values are:
`___BRAINY_TOP_LEFT="user_info dir scm"`
`___BRAINY_TOP_RIGHT="python ruby todo clock battery"`
`___BRAINY_BOTTOM="exitcode char"`

@ -0,0 +1,295 @@
#!/usr/bin/env bash
# Brainy Bash Prompt for Bash-it
# by MunifTanjim
#############
## Parsers ##
#############
____brainy_top_left_parse() {
ifs_old="${IFS}"
IFS="|"
args=( $1 )
IFS="${ifs_old}"
if [ -n "${args[3]}" ]; then
_TOP_LEFT+="${args[2]}${args[3]}"
fi
_TOP_LEFT+="${args[0]}${args[1]}"
if [ -n "${args[4]}" ]; then
_TOP_LEFT+="${args[2]}${args[4]}"
fi
_TOP_LEFT+=" "
}
____brainy_top_right_parse() {
ifs_old="${IFS}"
IFS="|"
args=( $1 )
IFS="${ifs_old}"
_TOP_RIGHT+=" "
if [ -n "${args[3]}" ]; then
_TOP_RIGHT+="${args[2]}${args[3]}"
fi
_TOP_RIGHT+="${args[0]}${args[1]}"
if [ -n "${args[4]}" ]; then
_TOP_RIGHT+="${args[2]}${args[4]}"
fi
__TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN + ${#args[1]} + ${#args[3]} + ${#args[4]} + 1 ))
(( __SEG_AT_RIGHT += 1 ))
}
____brainy_bottom_parse() {
ifs_old="${IFS}"
IFS="|"
args=( $1 )
IFS="${ifs_old}"
_BOTTOM+="${args[0]}${args[1]}"
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
}
____brainy_top() {
_TOP_LEFT=""
_TOP_RIGHT=""
__TOP_RIGHT_LEN=0
__SEG_AT_RIGHT=0
for seg in ${___BRAINY_TOP_LEFT}; do
info="$(___brainy_prompt_"${seg}")"
[ -n "${info}" ] && ____brainy_top_left_parse "${info}"
done
___cursor_right="\033[500C"
_TOP_LEFT+="${___cursor_right}"
for seg in ${___BRAINY_TOP_RIGHT}; do
info="$(___brainy_prompt_"${seg}")"
[ -n "${info}" ] && ____brainy_top_right_parse "${info}"
done
[ $__TOP_RIGHT_LEN -gt 0 ] && __TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN - 1 ))
___cursor_adjust="\033[${__TOP_RIGHT_LEN}D"
_TOP_LEFT+="${___cursor_adjust}"
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
}
____brainy_bottom() {
_BOTTOM=""
for seg in $___BRAINY_BOTTOM; do
info="$(___brainy_prompt_"${seg}")"
[ -n "${info}" ] && ____brainy_bottom_parse "${info}"
done
printf "\n%s" "${_BOTTOM}"
}
##############
## Segments ##
##############
___brainy_prompt_user_info() {
color=$bold_blue
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
if [ $(sudo -n id -u 2>&1 | grep 0) ]; then
color=$bold_red
fi
fi
box="[|]"
info="\u@\H"
if [ -n "${SSH_CLIENT}" ]; then
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
else
printf "%s|%s" "${color}" "${info}"
fi
}
___brainy_prompt_dir() {
color=$bold_yellow
box="[|]"
info="\w"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___brainy_prompt_scm() {
[ "${THEME_SHOW_SCM}" != "true" ] && return
color=$bold_green
box="$(scm_char) "
info="$(scm_prompt_info)"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___brainy_prompt_python() {
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
color=$bold_yellow
box="[|]"
info="$(python_version_prompt)"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
}
___brainy_prompt_ruby() {
[ "${THEME_SHOW_RUBY}" != "true" ] && return
color=$bold_white
box="[|]"
info="rb-$(ruby_version_prompt)"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
}
___brainy_prompt_todo() {
[ "${THEME_SHOW_TODO}" != "true" ] ||
[ -z "$(which todo.sh)" ] && return
color=$bold_white
box="[|]"
info="t:$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }' )"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}"
}
___brainy_prompt_clock() {
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
color=$THEME_CLOCK_COLOR
box="[|]"
info="$(date +"${THEME_CLOCK_FORMAT}")"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_purple}" "${box}"
}
___brainy_prompt_battery() {
[ ! -e $OSH/plugins/battery/battery.plugin.sh ] ||
[ "${THEME_SHOW_BATTERY}" != "true" ] && return
info=$(battery_percentage)
color=$bold_green
if [ "$info" -lt 50 ]; then
color=$bold_yellow
elif [ "$info" -lt 25 ]; then
color=$bold_red
fi
box="[|]"
ac_adapter_connected && info+="+"
[ "$info" == "100+" ] && info="AC"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___brainy_prompt_exitcode() {
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
color=$bold_purple
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
}
___brainy_prompt_char() {
color=$bold_white
prompt_char="${__BRAINY_PROMPT_CHAR_PS1}"
printf "%s|%s" "${color}" "${prompt_char}"
}
#########
## cli ##
#########
__brainy_show() {
typeset _seg=${1:-}
shift
export THEME_SHOW_${_seg}=true
}
__brainy_hide() {
typeset _seg=${1:-}
shift
export THEME_SHOW_${_seg}=false
}
_brainy_completion() {
local cur _action actions segments
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
_action="${COMP_WORDS[1]}"
actions="show hide"
segments="battery clock exitcode python ruby scm sudo todo"
case "${_action}" in
show)
COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") )
return 0
;;
hide)
COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") )
return 0
;;
esac
COMPREPLY=( $(compgen -W "${actions}" -- "${cur}") )
return 0
}
brainy() {
typeset action=${1:-}
shift
typeset segs=${*:-}
typeset func
case $action in
show)
func=__brainy_show;;
hide)
func=__brainy_hide;;
esac
for seg in ${segs}; do
seg=$(printf "%s" "${seg}" | tr '[:lower:]' '[:upper:]')
$func "${seg}"
done
}
complete -F _brainy_completion brainy
###############
## Variables ##
###############
export SCM_THEME_PROMPT_PREFIX=""
export SCM_THEME_PROMPT_SUFFIX=""
export RBENV_THEME_PROMPT_PREFIX=""
export RBENV_THEME_PROMPT_SUFFIX=""
export RBFU_THEME_PROMPT_PREFIX=""
export RBFU_THEME_PROMPT_SUFFIX=""
export RVM_THEME_PROMPT_PREFIX=""
export RVM_THEME_PROMPT_SUFFIX=""
export SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
export SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
THEME_SHOW_SUDO=${THEME_SHOW_SUDO:-"true"}
THEME_SHOW_SCM=${THEME_SHOW_SCM:-"true"}
THEME_SHOW_RUBY=${THEME_SHOW_RUBY:-"false"}
THEME_SHOW_PYTHON=${THEME_SHOW_PYTHON:-"false"}
THEME_SHOW_CLOCK=${THEME_SHOW_CLOCK:-"true"}
THEME_SHOW_TODO=${THEME_SHOW_TODO:-"false"}
THEME_SHOW_BATTERY=${THEME_SHOW_BATTERY:-"false"}
THEME_SHOW_EXITCODE=${THEME_SHOW_EXITCODE:-"true"}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$bold_white"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"}
__BRAINY_PROMPT_CHAR_PS1=${THEME_PROMPT_CHAR_PS1:-">"}
__BRAINY_PROMPT_CHAR_PS2=${THEME_PROMPT_CHAR_PS2:-"\\"}
___BRAINY_TOP_LEFT=${___BRAINY_TOP_LEFT:-"user_info dir scm"}
___BRAINY_TOP_RIGHT=${___BRAINY_TOP_RIGHT:-"python ruby todo clock battery"}
___BRAINY_BOTTOM=${___BRAINY_BOTTOM:-"exitcode char"}
############
## Prompt ##
############
__brainy_ps1() {
printf "%s%s%s" "$(____brainy_top)" "$(____brainy_bottom)" "${normal}"
}
__brainy_ps2() {
color=$bold_white
printf "%s%s%s" "${color}" "${__BRAINY_PROMPT_CHAR_PS2} " "${normal}"
}
_brainy_prompt() {
exitcode="$?"
PS1="$(__brainy_ps1)"
PS2="$(__brainy_ps2)"
}
safe_append_prompt_command _brainy_prompt

@ -0,0 +1,36 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_GIT_CHAR="${bold_green}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
is_vim_shell() {
if [ ! -z "$VIMRUNTIME" ]
then
echo "[${cyan}vim shell${normal}]"
fi
}
scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo " $(scm_char) (${white}$(scm_prompt_info)${normal})"
fi
}
prompt() {
PS1="${white}${background_blue} \u${normal}${background_blue}@${red}${background_blue}\h $(clock_prompt) ${reset_color}${normal} $(battery_charge)\n${bold_black}${background_white} \w ${normal}$(scm_prompt)$(is_vim_shell)\n${white}>${normal} "
}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue$background_white"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-" %H:%M:%S"}
safe_append_prompt_command prompt

@ -0,0 +1,10 @@
#!/usr/bin/env bash
function prompt_command() {
PS1="${green}\u@\h $(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue}${bold_blue} ${reset_color} ";
}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"}
safe_append_prompt_command prompt_command

@ -0,0 +1,20 @@
# git theming
ZSH_THEME_GIT_PROMPT_PREFIX="${bold_blue}(${yellow}%B"
ZSH_THEME_GIT_PROMPT_SUFFIX="%b${bold_blue})${reset_color} "
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="${bold_red}"
# LS colors, made with http://geoff.greer.fm/lscolors/
export LSCOLORS="Gxfxcxdxbxegedabagacad"
export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:'
function prompt_command() {
if [ "$(whoami)" = root ]; then no_color=$red; else no_color=$white; fi
PS1="${no_color}\u${reset_color}:${blue}\W/${reset_color} \[\$(scm_prompt_info)\]$ "
RPROMPT='[\t]'
}
safe_append_prompt_command prompt_command

271
themes/colours.theme.sh Normal file

@ -0,0 +1,271 @@
#!/usr/bin/env bash
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 $@)"
}
black="\[\e[0;30m\]"
red="\[\e[0;31m\]"
green="\[\e[0;32m\]"
yellow="\[\e[0;33m\]"
blue="\[\e[0;34m\]"
purple="\[\e[0;35m\]"
cyan="\[\e[0;36m\]"
white="\[\e[0;37m\]"
orange="\[\e[0;91m\]"
bold_black="\[\e[30;1m\]"
bold_red="\[\e[31;1m\]"
bold_green="\[\e[32;1m\]"
bold_yellow="\[\e[33;1m\]"
bold_blue="\[\e[34;1m\]"
bold_purple="\[\e[35;1m\]"
bold_cyan="\[\e[36;1m\]"
bold_white="\[\e[37;1m\]"
bold_orange="\[\e[91;1m\]"
underline_black="\[\e[30;4m\]"
underline_red="\[\e[31;4m\]"
underline_green="\[\e[32;4m\]"
underline_yellow="\[\e[33;4m\]"
underline_blue="\[\e[34;4m\]"
underline_purple="\[\e[35;4m\]"
underline_cyan="\[\e[36;4m\]"
underline_white="\[\e[37;4m\]"
underline_orange="\[\e[91;4m\]"
background_black="\[\e[40m\]"
background_red="\[\e[41m\]"
background_green="\[\e[42m\]"
background_yellow="\[\e[43m\]"
background_blue="\[\e[44m\]"
background_purple="\[\e[45m\]"
background_cyan="\[\e[46m\]"
background_white="\[\e[47;1m\]"
background_orange="\[\e[101m\]"
normal="\[\e[0m\]"
reset_color="\[\e[39m\]"
# These colors are meant to be used with `echo -e`
echo_black="\033[0;30m"
echo_red="\033[0;31m"
echo_green="\033[0;32m"
echo_yellow="\033[0;33m"
echo_blue="\033[0;34m"
echo_purple="\033[0;35m"
echo_cyan="\033[0;36m"
echo_white="\033[0;37;1m"
echo_orange="\033[0;91m"
echo_bold_black="\033[30;1m"
echo_bold_red="\033[31;1m"
echo_bold_green="\033[32;1m"
echo_bold_yellow="\033[33;1m"
echo_bold_blue="\033[34;1m"
echo_bold_purple="\033[35;1m"
echo_bold_cyan="\033[36;1m"
echo_bold_white="\033[37;1m"
echo_bold_orange="\033[91;1m"
echo_underline_black="\033[30;4m"
echo_underline_red="\033[31;4m"
echo_underline_green="\033[32;4m"
echo_underline_yellow="\033[33;4m"
echo_underline_blue="\033[34;4m"
echo_underline_purple="\033[35;4m"
echo_underline_cyan="\033[36;4m"
echo_underline_white="\033[37;4m"
echo_underline_orange="\033[91;4m"
echo_background_black="\033[40m"
echo_background_red="\033[41m"
echo_background_green="\033[42m"
echo_background_yellow="\033[43m"
echo_background_blue="\033[44m"
echo_background_purple="\033[45m"
echo_background_cyan="\033[46m"
echo_background_white="\033[47;1m"
echo_background_orange="\033[101m"
echo_normal="\033[0m"
echo_reset_color="\033[39m"

@ -0,0 +1,39 @@
# ------------------------------------------------------------------#
# FILE: cooperkid.zsh-theme #
# BY: Alfredo Bejarano #
# BASED ON: Mr Briggs by Matt Brigg (matt@mattbriggs.net) #
# ------------------------------------------------------------------#
SCM_THEME_PROMPT_DIRTY="${red}${reset_color}"
SCM_THEME_PROMPT_AHEAD="${yellow}${reset_color}"
SCM_THEME_PROMPT_CLEAN="${green}${reset_color}"
SCM_THEME_PROMPT_PREFIX=" "
SCM_THEME_PROMPT_SUFFIX=""
GIT_SHA_PREFIX="${blue}"
GIT_SHA_SUFFIX="${reset_color}"
function rvm_version_prompt {
if which rvm &> /dev/null; then
rvm=$(rvm-prompt) || return
if [ -n "$rvm" ]; then
echo -e "$rvm"
fi
fi
}
function git_short_sha() {
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX"
}
function prompt() {
local return_status=""
local ruby="${red}$(ruby_version_prompt)${reset_color}"
local user_host="${green}\h @ \w${reset_color}"
local git_branch="$(git_short_sha)${cyan}$(scm_prompt_info)${reset_color}"
local prompt_symbol=' '
local prompt_char="${purple}>_${reset_color} "
PS1="\n${user_host}${prompt_symbol}${ruby} ${git_branch} ${return_status}\n${prompt_char}"
}
safe_append_prompt_command prompt

@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Emoji-based theme to display source control management and
# virtual environment info beside the ordinary bash prompt.
# Theme inspired by:
# - Naming your Terminal tabs in OSX Lion - http://thelucid.com/2012/01/04/naming-your-terminal-tabs-in-osx-lion/
# - Bash_it sexy theme
# Demo:
# ┌ⓔ virtualenv 💁user @ 💻 host in 📁directory on 🌿branch {1} ↑1 ↓1 +1 •1 ⌀1 ✗
# └❯ cd .bash-it/themes/cupcake
# virtualenv prompts
VIRTUALENV_CHAR="ⓔ "
VIRTUALENV_THEME_PROMPT_PREFIX=""
VIRTUALENV_THEME_PROMPT_SUFFIX=""
# SCM prompts
SCM_NONE_CHAR=""
SCM_GIT_CHAR="[±] "
SCM_GIT_BEHIND_CHAR="${red}${normal}"
SCM_GIT_AHEAD_CHAR="${bold_green}${normal}"
SCM_GIT_UNTRACKED_CHAR="⌀"
SCM_GIT_UNSTAGED_CHAR="${bold_yellow}${normal}"
SCM_GIT_STAGED_CHAR="${bold_green}+${normal}"
SCM_THEME_PROMPT_DIRTY=""
SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
# Git status prompts
GIT_THEME_PROMPT_DIRTY=" ${red}${normal}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
GIT_THEME_PROMPT_PREFIX=""
GIT_THEME_PROMPT_SUFFIX=""
# ICONS =======================================================================
icon_start="┌"
icon_user="💁 "
icon_host=" @ 💻 "
icon_directory=" in 📁 "
icon_branch="🌿"
icon_end="└❯ "
# extra spaces ensure legiblity in prompt
# FUNCTIONS ===================================================================
# Display virtual environment info
function virtualenv_prompt {
if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=`basename "$VIRTUAL_ENV"`
echo -e "$VIRTUALENV_CHAR$virtualenv "
fi
}
# Rename tab
function tabname {
printf "\e]1;$1\a"
}
# Rename window
function winname {
printf "\e]2;$1\a"
}
# PROMPT OUTPUT ===============================================================
# Displays the current prompt
function prompt_command() {
PS1="\n${icon_start}$(virtualenv_prompt)${icon_user}${bold_red}\u${normal}${icon_host}${bold_cyan}\h${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${white}$(scm_prompt_info)${normal}\n${icon_end}"
PS2="${icon_end}"
}
# Runs prompt (this bypasses oh-my-bash $PROMPT setting)
safe_append_prompt_command prompt_command

@ -0,0 +1,129 @@
#!/usr/bin/env bash
# Theme inspired on:
# - Ronacher's dotfiles (mitsuhikos) - http://github.com/mitsuhiko/dotfiles/tree/master/bash/
# - Glenbot - http://theglenbot.com/custom-bash-shell-for-development/
# - My extravagant zsh - http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
# - Monokai colors - http://monokai.nl/blog/2006/07/15/textmate-color-theme/
# - Bash_it modern theme
#
# Screenshot: http://goo.gl/VCmX5
# by Jesus de Mula <jesus@demula.name>
# For the real Monokai colors you should add these to your .XDefaults or
# terminal configuration:
#! ----------------------------------------------------------- TERMINAL COLORS
#! monokai - http://www.monokai.nl/blog/2006/07/15/textmate-color-theme/
#*background: #272822
#*foreground: #E2DA6E
#*color0: black
#! mild red
#*color1: #CD0000
#! light green
#*color2: #A5E02D
#! orange (yellow)
#*color3: #FB951F
#! "dark" blue
#*color4: #076BCC
#! hot pink
#*color5: #F6266C
#! cyan
#*color6: #64D9ED
#! gray
#*color7: #E5E5E5
# ----------------------------------------------------------------- COLOR CONF
D_DEFAULT_COLOR="${normal}"
D_INTERMEDIATE_COLOR="${white}"
D_USER_COLOR="${purple}"
D_SUPERUSER_COLOR="${red}"
D_MACHINE_COLOR="${cyan}"
D_DIR_COLOR="${green}"
D_SCM_COLOR="${yellow}"
D_BRANCH_COLOR="${yellow}"
D_CHANGES_COLOR="${white}"
D_CMDFAIL_COLOR="${red}"
D_VIMSHELL_COLOR="${cyan}"
# ------------------------------------------------------------------ FUNCTIONS
case $TERM in
xterm*)
TITLEBAR="\033]0;\w\007"
;;
*)
TITLEBAR=""
;;
esac
is_vim_shell() {
if [ ! -z "$VIMRUNTIME" ];
then
echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\
vim shell${D_DEFAULT_COLOR} "
fi
}
mitsuhikos_lastcommandfailed() {
code=$?
if [ $code != 0 ];
then
echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\
$code ${D_DEFAULT_COLOR}"
fi
}
# vcprompt for scm instead of oh-my-bash default
demula_vcprompt() {
if [ ! -z "$VCPROMPT_EXECUTABLE" ];
then
local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\
${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
$VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT"
fi
}
# checks if the plugin is installed before calling battery_charge
safe_battery_charge() {
if [ -e "${OSH}/plugins/battery/battery.plugin.sh" ];
then
battery_charge
fi
}
# -------------------------------------------------------------- PROMPT OUTPUT
prompt() {
local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed)
local SAVE_CURSOR='\033[s'
local RESTORE_CURSOR='\033[u'
local MOVE_CURSOR_RIGHTMOST='\033[500C'
local MOVE_CURSOR_5_LEFT='\033[5D'
if [ $(uname) = "Linux" ];
then
PS1="${TITLEBAR}
${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\
$(safe_battery_charge)${RESTORE_CURSOR}\
${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
${LAST_COMMAND_FAILED}\
$(demula_vcprompt)\
$(is_vim_shell)
${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
else
PS1="${TITLEBAR}
${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
${LAST_COMMAND_FAILED}\
$(demula_vcprompt)\
$(is_vim_shell)\
$(safe_battery_charge)
${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
fi
PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
}
# Runs prompt (this bypasses oh-my-bash $PROMPT setting)
safe_append_prompt_command prompt

1
themes/dos/dos.theme.sh Normal file

@ -0,0 +1 @@
PROMPT="\w>>"

@ -0,0 +1,72 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=''
SCM_THEME_PROMPT_CLEAN=''
SCM_GIT_CHAR="${bold_cyan}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
if [ ! -z $RVM_THEME_PROMPT_COLOR ]; then
RVM_THEME_PROMPT_COLOR=$(eval echo $`echo ${RVM_THEME_PROMPT_COLOR}`);
else
RVM_THEME_PROMPT_COLOR="${red}"
fi
RVM_THEME_PROMPT_PREFIX="(${RVM_THEME_PROMPT_COLOR}rb${normal}: "
RVM_THEME_PROMPT_SUFFIX=") "
if [ ! -z $VIRTUALENV_THEME_PROMPT_COLOR ]; then
VIRTUALENV_THEME_PROMPT_COLOR=$(eval echo $`echo ${VIRTUALENV_THEME_PROMPT_COLOR}`);
else
VIRTUALENV_THEME_PROMPT_COLOR="${green}"
fi
VIRTUALENV_THEME_PROMPT_PREFIX="(${VIRTUALENV_THEME_PROMPT_COLOR}py${normal}: "
VIRTUALENV_THEME_PROMPT_SUFFIX=") "
if [ ! -z $THEME_PROMPT_HOST_COLOR ]; then
THEME_PROMPT_HOST_COLOR=$(eval echo $`echo ${THEME_PROMPT_HOST_COLOR}`);
else
THEME_PROMPT_HOST_COLOR="$blue"
fi
doubletime_scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]; then
return
elif [ $CHAR = $SCM_GIT_CHAR ]; then
echo "$(git_prompt_status)"
else
echo "[$(scm_prompt_info)]"
fi
}
function prompt_setter() {
# Save history
history -a
history -c
history -r
PS1="
$(clock_prompt) $(scm_char) [${THEME_PROMPT_HOST_COLOR}\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w
$(doubletime_scm_prompt)$reset_color $ "
PS2='> '
PS4='+ '
}
safe_append_prompt_command prompt_setter
git_prompt_status() {
local git_status_output
git_status_output=$(git status 2> /dev/null )
if [ -n "$(echo $git_status_output | grep 'Changes not staged')" ]; then
git_status="${bold_red}$(scm_prompt_info)"
elif [ -n "$(echo $git_status_output | grep 'Changes to be committed')" ]; then
git_status="${bold_yellow}$(scm_prompt_info) ^"
elif [ -n "$(echo $git_status_output | grep 'Untracked files')" ]; then
git_status="${bold_cyan}$(scm_prompt_info) +"
elif [ -n "$(echo $git_status_output | grep 'nothing to commit')" ]; then
git_status="${bold_green}$(scm_prompt_info) ${green}"
else
git_status="$(scm_prompt_info)"
fi
echo "[$git_status${normal}]"
}

@ -0,0 +1,18 @@
#!/usr/bin/env bash
source "$OSH/themes/doubletime/doubletime.theme.sh"
function prompt_setter() {
# Save history
history -a
history -c
history -r
PS1="
$(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)
\w
$(doubletime_scm_prompt)$reset_color $ "
PS2='> '
PS4='+ '
}
safe_append_prompt_command prompt_setter

@ -0,0 +1,18 @@
#!/usr/bin/env bash
source "$OSH/themes/doubletime/doubletime.theme.sh"
function prompt_setter() {
# Save history
history -a
history -c
history -r
PS1="
$(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)
\w
$(doubletime_scm_prompt)$reset_color $ "
PS2='> '
PS4='+ '
}
safe_append_prompt_command prompt_setter

@ -0,0 +1,98 @@
#!/usr/bin/env bash
# Simplistic one-liner theme to display source control management info beside
# the ordinary Linux bash prompt.
#
# Demo:
#
# [ritola@localhost ~]$ cd .bash-it/themes/dulcie
# [ritola@localhost |master ✓| dulcie]$ # This is single line mode
# |bash-it|± master ✓|
# [ritola@localhost dulcie]$ # In multi line, the SCM info is in the separate line
#
# Configuration. Change these by adding them in your .bash_profile
DULCIE_COLOR=${DULCIE_COLOR:=1} # 0 = monochrome, 1 = colorful
DULCIE_MULTILINE=${DULCIE_MULTILINE:=1} # 0 = Single line, 1 = SCM in separate line
dulcie_color() {
echo -en "\[\e[38;5;${1}m\]"
}
dulcie_background() {
echo -en "\[\e[48;5;${1}m\]"
}
dulcie_prompt() {
color_user_root=$(dulcie_color 169)
color_user_nonroot="${green}"
color_host_local=$(dulcie_color 230)
color_host_remote=$(dulcie_color 214)
color_rootdir=$(dulcie_color 117)
color_workingdir=$(dulcie_color 117)
background_scm=$(dulcie_background 238)
SCM_THEME_ROOT_SUFFIX="|$(scm_char) "
# Set colors
if [ "${DULCIE_COLOR}" -eq "1" ]; then
if [[ $EUID -ne 0 ]]; then
color_user="${color_user_nonroot}"
else
color_user="${color_user_root}"
fi
if [[ -n "${SSH_CLIENT}" ]]; then
color_host="${color_host_remote}"
else
color_host="${color_host_local}"
fi
DULCIE_USER="${color_user}\u${reset_color}"
DULCIE_HOST="${color_host}\h${reset_color}"
DULCIE_WORKINGDIR="${color_workingdir}\W${reset_color}"
DULCIE_PROMPTCHAR="${color_user}"'\$'"${reset_color}"
SCM_THEME_PROMPT_DIRTY=" ${red}${reset_color}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
DULCIE_SCM_BACKGROUND="${background_scm}"
DULCIE_SCM_DIR_COLOR="${color_rootdir}"
SCM_THEME_ROOT_SUFFIX="${reset_color}${SCM_THEME_ROOT_SUFFIX}"
SCM_THEME_PROMPT_DIRTY=" $(dulcie_color 1)${reset_color}"
SCM_THEME_PROMPT_CLEAN=" $(dulcie_color 10)${reset_color}"
else
DULCIE_USER='\u'
DULCIE_HOST='\h'
DULCIE_WORKINGDIR='\W'
DULCIE_PROMPTCHAR='\$'
DULCIE_SCM_BACKGROUND=""
DULCIE_SCM_DIR_COLOR=""
SCM_THEME_DIR_COLOR=""
SCM_THEME_PROMPT_DIRTY=" ✗"
SCM_THEME_PROMPT_CLEAN=" ✓"
fi
# Change terminal title
printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"
# Open the new terminal in the same directory
declare -f __vte_osc7 > /dev/null && __vte_osc7
PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]"
if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then
PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}${reset_color} ${DULCIE_WORKINGDIR}]"
if [[ "$(scm_prompt_info)" ]]; then
SCM_THEME_PROMPT_PREFIX="${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}"
SCM_THEME_PROMPT_SUFFIX="|${normal}"
PS1="$(scm_prompt_info)\n${PS1}"
fi
else
SCM_THEME_PROMPT_PREFIX=" ${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}"
SCM_THEME_PROMPT_SUFFIX="|${normal}"
PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]"
fi
PS1="${PS1}${DULCIE_PROMPTCHAR} "
}
safe_append_prompt_command dulcie_prompt

24
themes/duru/duru.theme.sh Normal file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_PREFIX="${cyan} on ${green}"
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${red}with changes"
SCM_THEME_PROMPT_CLEAN=""
venv() {
if [ ! -z "$VIRTUAL_ENV" ]
then
local env=$VIRTUAL_ENV
echo "${gray} in ${orange}${env##*/} "
fi
}
last_two_dirs() {
pwd|rev|awk -F / '{print $1,$2}'|rev|sed s_\ _/_|sed "s|$(sed 's,\/,,'<<<$HOME)|~|g"
}
prompt() {
PS1="${yellow}# ${reset_color}$(last_two_dirs)$(scm_prompt_info)${reset_color}$(venv)${reset_color} ${cyan}\n> ${reset_color}"
}
safe_append_prompt_command prompt

@ -0,0 +1,42 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"
function get_hour_color {
hour_color=$red
min=$(date +%M)
if [ "$min" -lt "15" ]; then
hour_color=$white
elif [ "$min" -lt "30" ]; then
hour_color=$green
elif [ "$min" -lt "45" ]; then
hour_color=$yellow
else
hour_color=$red
fi
echo "$hour_color"
}
__emperor_clock() {
THEME_CLOCK_COLOR=$(get_hour_color)
clock_prompt
}
function prompt_command() {
PS1="\n$(__emperor_clock)${purple}\h ${reset_color}in ${prompt_color}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}${reset_color} "
}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H "}
safe_append_prompt_command prompt_command

16
themes/envy/envy.theme.sh Normal file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
function prompt_command() {
PS1="\n${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}${reset_color} "
}
safe_append_prompt_command prompt_command

60
themes/font/font.theme.sh Normal file

@ -0,0 +1,60 @@
#!/usr/bin/env bash
#
# One line prompt showing the following configurable information
# for git:
# time (virtual_env) username@hostname pwd git_char|git_branch git_dirty_status|→
#
# The → arrow shows the exit status of the last command:
# - bold green: 0 exit status
# - bold red: non-zero exit status
#
# Example outside git repo:
# 07:45:05 user@host ~ →
#
# Example inside clean git repo:
# 07:45:05 user@host .oh-my-bash ±|master|→
#
# Example inside dirty git repo:
# 07:45:05 user@host .oh-my-bash ±|master ✗|→
#
# Example with virtual environment:
# 07:45:05 (venv) user@host ~ →
#
SCM_NONE_CHAR=''
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_PREFIX="${green}|"
SCM_THEME_PROMPT_SUFFIX="${green}|"
SCM_GIT_SHOW_MINIMAL_INFO=true
CLOCK_THEME_PROMPT_PREFIX=''
CLOCK_THEME_PROMPT_SUFFIX=' '
THEME_SHOW_CLOCK=true
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$bold_blue"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"}
VIRTUALENV_THEME_PROMPT_PREFIX='('
VIRTUALENV_THEME_PROMPT_SUFFIX=') '
function prompt_command() {
# This needs to be first to save last command return code
local RC="$?"
hostname="${bold_black}\u@\h"
virtualenv="${white}$(virtualenv_prompt)"
# Set return status color
if [[ ${RC} == 0 ]]; then
ret_status="${bold_green}"
else
ret_status="${bold_red}"
fi
# Append new history lines to history file
history -a
PS1="$(clock_prompt)${virtualenv}${hostname} ${bold_cyan}\W $(scm_prompt_char_info)${ret_status}${normal}"
}
safe_append_prompt_command prompt_command

@ -0,0 +1,41 @@
# scm theming
SCM_THEME_PROMPT_PREFIX="${yellow}("
SCM_THEME_PROMPT_SUFFIX=")${normal}"
SCM_THEME_PROMPT_DIRTY="*"
SCM_THEME_PROMPT_CLEAN=""
SCM_GIT_CHAR="g"
SCM_SVN_CHAR="s"
SCM_HG_CHAR="h"
### TODO: openSUSE has already colors enabled, check if those differs from stock
# LS colors, made with http://geoff.greer.fm/lscolors/
# export LSCOLORS="Gxfxcxdxbxegedabagacad"
# export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:'
scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo "$(scm_prompt_info) "
fi
}
pure_prompt() {
ps_host="${green}\h${normal}";
ps_user_mark="${bold}\$${normal}";
ps_root_mark="${normal}§"
ps_path="${normal}\w";
# make it work
case $(id -u) in
0) PS1="$ps_host $ps_path $(scm_prompt)$ps_root_mark "
;;
*) PS1="$ps_host $ps_path $(scm_prompt)$ps_user_mark "
;;
esac
}
safe_append_prompt_command pure_prompt

@ -0,0 +1,200 @@
#!/usr/bin/env bash
#
# This theme was obviously inspired a lot by
#
# - Demula theme
#
# which in itself was inspired by :
#
# - Ronacher's dotfiles (mitsuhikos) - http://github.com/mitsuhiko/dotfiles/tree/master/bash/
# - Glenbot - http://theglenbot.com/custom-bash-shell-for-development/
# - My extravagant zsh - http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
# - Monokai colors - http://monokai.nl/blog/2006/07/15/textmate-color-theme/
# - Bash_it modern theme
#
# Hawaii50 theme supports :
#
# - configurable directory length
# - hg, svn, git detection (I work in all of them)
# - virtualenv, rvm + gemsets
#
# Screenshot: http://i.imgur.com/4IAMJ.png
#
# by Ryan Kanno <ryankanno@localkinegrinds.com>
#
# And yes, we code out in Hawaii. :D
#
# Note: I also am really new to this bash scripting game, so if you see things
# that are flat out wrong, or if you think of something neat, just send a pull
# request. This probably only works on a Mac - as some functions are OS
# specific like getting ip, etc.
#
# IMPORTANT THINGS TO CHANGE ==================================================
# Show IP in prompt
# One thing to be weary about if you have slow Internets
IP_ENABLED=1
# virtual prompts
VIRTUAL_PROMPT_ENABLED=1
# COLORS ======================================================================
ORANGE='\[\e[0;33m\]'
DEFAULT_COLOR="${white}"
USER_COLOR="${purple}"
SUPERUSER_COLOR="${red}"
MACHINE_COLOR=$ORANGE
IP_COLOR=$ORANGE
DIRECTORY_COLOR="${green}"
VE_COLOR="${cyan}"
RVM_COLOR="${cyan}"
REF_COLOR="${purple}"
# SCM prompts
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_THEME_PROMPT_PREFIX=' on '
SCM_THEME_PROMPT_SUFFIX=''
# rvm prompts
RVM_THEME_PROMPT_PREFIX=''
RVM_THEME_PROMPT_SUFFIX=''
# virtualenv prompts
VIRTUALENV_THEME_PROMPT_PREFIX=''
VIRTUALENV_THEME_PROMPT_SUFFIX=''
VIRTUAL_THEME_PROMPT_PREFIX=' using '
VIRTUAL_THEME_PROMPT_SUFFIX=''
# Max length of PWD to display
MAX_PWD_LENGTH=20
# Max length of Git Hex to display
MAX_GIT_HEX_LENGTH=5
# IP address
IP_SEPARATOR=', '
# FUNCS =======================================================================
function get_ip_info {
myip=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
echo -e "$(ips | sed -e :a -e '$!N;s/\n/${IP_SEPARATOR}/;ta' | sed -e 's/127\.0\.0\.1\${IP_SEPARATOR}//g'), ${myip}"
}
# Displays ip prompt
function ip_prompt_info() {
if [[ $IP_ENABLED == 1 ]]; then
echo -e " ${DEFAULT_COLOR}(${IP_COLOR}$(get_ip_info)${DEFAULT_COLOR})"
fi
}
# Displays virtual info prompt (virtualenv/rvm)
function virtual_prompt_info() {
local virtual_env_info=$(virtualenv_prompt)
local rvm_info=$(ruby_version_prompt)
local virtual_prompt=""
local prefix=${VIRTUAL_THEME_PROMPT_PREFIX}
local suffix=${VIRTUAL_THEME_PROMPT_SUFFIX}
# If no virtual info, just return
[[ -z "$virtual_env_info" && -z "$rvm_info" ]] && return
# If virtual_env info present, append to prompt
[[ -n "$virtual_env_info" ]] && virtual_prompt="virtualenv: ${VE_COLOR}$virtual_env_info${DEFAULT_COLOR}"
if [[ -n "$rvm_info" ]]
then
[[ -n "$virtual_env_info" ]] && virtual_prompt="$virtual_prompt, "
virtual_prompt="${virtual_prompt}rvm: ${RVM_COLOR}$rvm_info${DEFAULT_COLOR}"
fi
echo -e "$prefix$virtual_prompt$suffix"
}
# Parse git info
function git_prompt_info() {
if [[ -n $(git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then
state=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else
state=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi
prefix=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
suffix=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
commit_id=$(git rev-parse HEAD 2>/dev/null) || return
echo -e "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${commit_id:0:$MAX_GIT_HEX_LENGTH}$state$suffix"
}
# Parse hg info
function hg_prompt_info() {
if [[ -n $(hg status 2> /dev/null) ]]; then
state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else
state=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi
prefix=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
suffix=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
branch=$(hg summary 2> /dev/null | grep branch | awk '{print $2}')
changeset=$(hg summary 2> /dev/null | grep parent | awk '{print $2}')
echo -e "$prefix${REF_COLOR}${branch}${DEFAULT_COLOR}:${changeset#*:}$state$suffix"
}
# Parse svn info
function svn_prompt_info() {
if [[ -n $(svn status --ignore-externals -q 2> /dev/null) ]]; then
state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else
state=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi
prefix=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
suffix=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
ref=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return
[[ -z $ref ]] && return
revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' )
echo -e "$prefix${REF_COLOR}$ref${DEFAULT_COLOR}:$revision$state$suffix"
}
# Displays last X characters of pwd
function limited_pwd() {
# Replace $HOME with ~ if possible
RELATIVE_PWD=${PWD/#$HOME/\~}
local offset=$((${#RELATIVE_PWD}-$MAX_PWD_LENGTH))
if [ $offset -gt "0" ]
then
local truncated_symbol="..."
TRUNCATED_PWD=${RELATIVE_PWD:$offset:$MAX_PWD_LENGTH}
echo -e "${truncated_symbol}/${TRUNCATED_PWD#*/}"
else
echo -e "${RELATIVE_PWD}"
fi
}
# Displays the current prompt
function prompt() {
local UC=$USER_COLOR
[ $UID -eq "0" ] && UC=$SUPERUSER_COLOR
if [[ $VIRTUAL_PROMPT_ENABLED == 1 ]]; then
PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h$(ip_prompt_info) ${DEFAULT_COLOR}in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_prompt_info)$(scm_prompt_info)${reset_color} \$ "
else
PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h$(ip_prompt_info) ${DEFAULT_COLOR}in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(scm_prompt_info)${reset_color} \$ "
fi
PS2='> '
PS4='+ '
}
safe_append_prompt_command prompt

@ -0,0 +1,59 @@
#!/usr/bin/env bash
SCM_GIT_CHAR="± "
SCM_HG_CHAR="☿ "
SCM_SVN_CHAR="⑆ "
SCM_NONE_CHAR=""
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX="|"
SCM_THEME_PROMPT_SUFFIX="${green}| "
SCM_GIT_AHEAD_CHAR="${green}+"
SCM_GIT_BEHIND_CHAR="${red}-"
GIT_THEME_PROMPT_DIRTY=" ${bold_red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX="${cyan}|"
GIT_THEME_PROMPT_SUFFIX="${cyan}| "
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="| "
VIRTUALENV_THEME_PROMPT_PREFIX="|"
VIRTUALENV_THEME_PROMPT_SUFFIX="| "
RBENV_THEME_PROMPT_PREFIX="|"
RBENV_THEME_PROMPT_SUFFIX="| "
RBFU_THEME_PROMPT_PREFIX="|"
RBFU_THEME_PROMPT_SUFFIX="| "
function rvm_version_prompt {
if which rvm &> /dev/null; then
rvm_current=$(rvm tools identifier) || return
rvm_default=$(rvm strings default) || return
[ "$rvm_current" != "$rvm_default" ] && ( echo -e "$RVM_THEME_PROMPT_PREFIX$rvm_current$RVM_THEME_PROMPT_SUFFIX" )
fi
}
function git_prompt_info {
git_prompt_vars
echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX"
}
LAST_PROMPT=""
function prompt_command() {
local new_PS1="${bold_cyan}$(scm_char)${yellow}$(ruby_version_prompt)${green}\w $(scm_prompt_info)"
local new_prompt=$(PS1="$new_PS1" "$BASH" --norc -i </dev/null 2>&1 | sed -n '${s/^\(.*\)exit$/\1/p;}')
if [ "$LAST_PROMPT" = "$new_prompt" ]; then
new_PS1=""
else
LAST_PROMPT="$new_prompt"
fi
local wrap_char=""
[[ ${#new_PS1} -gt $(($COLUMNS/1)) ]] && wrap_char="\n"
PS1="${new_PS1}${green}${wrap_char}${reset_color} "
}
safe_append_prompt_command prompt_command

@ -0,0 +1,38 @@
# This is combination of works from two different people which I combined for my requirement.
# Original PS1 was from reddit user /u/Allevil669 which I found in thread: https://www.reddit.com/r/linux/comments/1z33lj/linux_users_whats_your_favourite_bash_prompt/
# I used that PS1 to the bash-it theme 'morris', and customized it to my liking. All credits to /u/Allevil669 and morris.
#
# prompt theming
# added TITLEBAR for updating the tab and window titles with the pwd
case $TERM in
xterm*)
TITLEBAR=$(printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}")
;;
screen)
TITLEBAR=$(printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}")
;;
*)
TITLEBAR=""
;;
esac
if [ "$?" == "0" ]
then
SC="${green}^_^";
else
SC="${red}T_T";
fi
BC=`battery_percentage`
function prompt_command() {
#PS1="${TITLEBAR}[\u@\h \W $(scm_prompt_info)]\$ "
PS1="\n${cyan}┌─${bold_white}[\u@\h]${cyan}${bold_yellow}(\w)$(scm_prompt_info)\n${cyan}└─${bold_green}[\A]-${green}($BC%)${bold_cyan}-[${green}${bold_green}\$${bold_cyan}]${green} "
}
# scm theming
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX="${bold_cyan}("
SCM_THEME_PROMPT_SUFFIX="${bold_cyan})${reset_color}"
safe_append_prompt_command prompt_command

33
themes/luan/luan.theme.sh Normal file

@ -0,0 +1,33 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX="(${yellow}"
SCM_THEME_PROMPT_SUFFIX="${normal})"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX="(${yellow}"
GIT_THEME_PROMPT_SUFFIX="${normal})"
RVM_THEME_PROMPT_PREFIX=""
RVM_THEME_PROMPT_SUFFIX=""
function prompt_command() {
dtime="$(clock_prompt)"
user_host="${green}\u@${cyan}\h${normal}"
current_dir="${bold_blue}\w${normal}"
rvm_ruby="${bold_red}$(ruby_version_prompt)${normal}"
git_branch="$(scm_prompt_info)${normal}"
prompt="${bold_green}\$${normal} "
arrow="${bold_white}${normal} "
prompt="${bold_green}\$${normal} "
PS1="${dtime}${user_host}:${current_dir} ${rvm_ruby} ${git_branch}
$arrow $prompt"
}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$yellow"}
THEME_CLOCK_FORMAT=${THEME_TIME_FORMAT:-"%I:%M:%S "}
safe_append_prompt_command prompt_command

@ -0,0 +1,130 @@
# Mairan Bash Prompt, inspired by "Zork"
if tput setaf 1 &> /dev/null; then
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
MAGENTA=$(tput setaf 9)
ORANGE=$(tput setaf 172)
GREEN=$(tput setaf 190)
PURPLE=$(tput setaf 141)
WHITE=$(tput setaf 0)
else
MAGENTA=$(tput setaf 5)
ORANGE=$(tput setaf 4)
GREEN=$(tput setaf 2)
PURPLE=$(tput setaf 1)
WHITE=$(tput setaf 7)
fi
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
MAGENTA="\033[1;31m"
ORANGE="\033[1;33m"
GREEN="\033[1;32m"
PURPLE="\033[1;35m"
WHITE="\033[1;37m"
BOLD=""
RESET="\033[m"
fi
# prompt_symbol='λ'
# prompt_symbol='⚡'
prompt_symbol=''
BRACKET_COLOR=$ORANGE
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_GIT_CHAR="${bold_green}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
#Mysql Prompt
export MYSQL_PS1="(\u@\h) [\d]> "
case $TERM in
xterm*)
TITLEBAR="\[\033]0;\w\007\]"
;;
*)
TITLEBAR=""
;;
esac
PS3=">> "
__my_rvm_ruby_version() {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
local full="$version$gemset"
[ "$full" != "" ] && echo "[$full]"
}
is_vim_shell() {
if [ ! -z "$VIMRUNTIME" ]
then
echo "[${cyan}vim shell${normal}]"
fi
}
modern_scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo "[$(scm_char)][$GREEN$(scm_prompt_info)]"
fi
}
# show chroot if exist
chroot(){
if [ -n "$debian_chroot" ]
then
my_ps_chroot="${bold_cyan}$debian_chroot${normal}";
echo "($my_ps_chroot)";
fi
}
# show virtualenvwrapper
my_ve(){
if [ -n "$VIRTUAL_ENV" ]
then
my_ps_ve="${bold_purple}$ve${normal}";
echo "($my_ps_ve)";
fi
echo "";
}
prompt() {
my_ps_host="$BOLD$ORANGE\h${normal}";
# yes, these are the the same for now ...
my_ps_host_root="$ORANGE\h${normal}";
my_ps_user="$BOLD$GREEN\u${normal}"
my_ps_root="${bold_red}\u${normal}";
if [ -n "$VIRTUAL_ENV" ]
then
ve=`basename $VIRTUAL_ENV`;
fi
# nice prompt
case "`id -u`" in
0) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR}
└─▪ ${prompt_symbol} ${normal}"
;;
*) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(modern_scm_prompt)${normal}$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR}
└─▪ ${prompt_symbol} ${normal}"
;;
esac
}
PS2="└─▪ "
safe_append_prompt_command prompt

@ -0,0 +1,34 @@
# ------------------------------------------------------------------#
# FILE: mbriggs.zsh-theme #
# BY: Matt Briggs (matt@mattbriggs.net) #
# BASED ON: smt by Stephen Tudor (stephen@tudorstudio.com) #
# ------------------------------------------------------------------#
SCM_THEME_PROMPT_DIRTY="${red}${reset_color}"
SCM_THEME_PROMPT_AHEAD="${red}!${reset_color}"
SCM_THEME_PROMPT_CLEAN="${green}${reset_color}"
SCM_THEME_PROMPT_PREFIX=" "
SCM_THEME_PROMPT_SUFFIX=""
GIT_SHA_PREFIX=" ${yellow}"
GIT_SHA_SUFFIX="${reset_color}"
function git_short_sha() {
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX"
}
function prompt() {
local return_status=""
local ruby="${red}$(ruby_version_prompt)${reset_color}"
local user_host="${green}\h${reset_color}"
local current_path="\w"
local n_commands="\!"
local git_branch="$(git_short_sha)$(scm_prompt_info)"
local prompt_symbol='λ'
local open='('
local close=')'
local prompt_char=' \$ '
PS1="\n${n_commands} ${user_host} ${prompt_symbol} ${ruby} ${open}${current_path}${git_branch}${close}${return_status}\n${prompt_char}"
}
safe_append_prompt_command prompt

@ -0,0 +1,12 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_PREFIX="${cyan}(${green}"
SCM_THEME_PROMPT_SUFFIX="${cyan})"
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${green}"
prompt() {
PS1="$(scm_prompt_info)${reset_color} ${cyan}\W${reset_color} "
}
safe_append_prompt_command prompt

@ -0,0 +1,56 @@
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_GIT_CHAR="${bold_green}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
case $TERM in
xterm*)
TITLEBAR="\[\033]0;\w\007\]"
;;
*)
TITLEBAR=""
;;
esac
PS3=">> "
is_vim_shell() {
if [ ! -z "$VIMRUNTIME" ]
then
echo "[${cyan}vim shell${normal}]"
fi
}
modern_scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo "[$(scm_char)][$(scm_prompt_info)]"
fi
}
prompt() {
if [ $? -ne 0 ]
then
# Yes, the indenting on these is weird, but it has to be like
# this otherwise it won't display properly.
PS1="${TITLEBAR}${bold_red}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]${reset_color}$(modern_scm_prompt)[${cyan}\W${normal}]$(is_vim_shell)
${bold_red}└─▪${normal} "
else
PS1="${TITLEBAR}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]$(modern_scm_prompt)[${cyan}\W${normal}]$(is_vim_shell)
└─▪ "
fi
}
PS2="└─▪ "
safe_append_prompt_command prompt

@ -0,0 +1,56 @@
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_GIT_CHAR="${bold_green}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
case $TERM in
xterm*)
TITLEBAR="\[\033]0;\w\007\]"
;;
*)
TITLEBAR=""
;;
esac
PS3=">> "
is_vim_shell() {
if [ ! -z "$VIMRUNTIME" ]
then
echo "[${cyan}vim shell${normal}]"
fi
}
modern_scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo "[$(scm_char)][$(scm_prompt_info)]"
fi
}
prompt() {
if [ $? -ne 0 ]
then
# Yes, the indenting on these is weird, but it has to be like
# this otherwise it won't display properly.
PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(modern_scm_prompt)[${cyan}\W${normal}][$(battery_charge)]$(is_vim_shell)
${bold_red}└─▪${normal} "
else
PS1="${TITLEBAR}┌─$(modern_scm_prompt)[${cyan}\W${normal}][$(battery_charge)]$(is_vim_shell)
└─▪ "
fi
}
PS2="└─▪ "
safe_append_prompt_command prompt

@ -0,0 +1,28 @@
# prompt theming
# added TITLEBAR for updating the tab and window titles with the pwd
case $TERM in
xterm*)
TITLEBAR=$(printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}")
;;
screen)
TITLEBAR=$(printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}")
;;
*)
TITLEBAR=""
;;
esac
function prompt_command() {
PS1="${TITLEBAR}[\u@\h \W $(scm_prompt_info)]\$ "
}
# scm theming
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX="${green}("
SCM_THEME_PROMPT_SUFFIX="${green})${reset_color}"
safe_append_prompt_command prompt_command

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# n0qorg theme by Florian Baumann <flo@noqqe.de>
## look-a-like
# host directory (branch*)»
# for example:
# ananas ~/Code/bash-it/themes (master*)»
function prompt_command() {
PS1="${bold_blue}[$(hostname)]${normal} \w${normal} ${bold_white}[$(git_prompt_info)]${normal}» "
}
safe_append_prompt_command prompt_command
## git-theme
# feel free to change git chars.
GIT_THEME_PROMPT_DIRTY="${bold_blue}*${bold_white}"
GIT_THEME_PROMPT_CLEAN=""
GIT_THEME_PROMPT_PREFIX="${bold_blue}(${bold_white}"
GIT_THEME_PROMPT_SUFFIX="${bold_blue})"
## alternate chars
#
SCM_THEME_PROMPT_DIRTY="*"
SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_PREFIX="("
SCM_THEME_PROMPT_SUFFIX=")"

Some files were not shown because too many files have changed in this diff Show More