Compare commits
189 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eced6802d0 | ||
|
|
02f6654841 | ||
|
|
7b5f758eba | ||
|
|
6f02b8d194 | ||
|
|
c8ef6c9146 | ||
|
|
8ae2b1e73d | ||
|
|
ffc1701c0a | ||
|
|
96586dd575 | ||
|
|
c59886b8ab | ||
|
|
5c6306deb7 | ||
|
|
6093ecbb60 | ||
|
|
e289549a50 | ||
|
|
9d7738d14d | ||
|
|
7827907154 | ||
|
|
0ed6f045f6 | ||
|
|
4607ee7452 | ||
|
|
0eab2962d3 | ||
|
|
0e77a94140 | ||
|
|
a0ba2a1787 | ||
|
|
0dd01da4b7 | ||
|
|
7fb7e27921 | ||
|
|
751d3e2496 | ||
|
|
e8342c1d97 | ||
|
|
2d56cc4167 | ||
|
|
25c1c8978e | ||
|
|
133e48229a | ||
|
|
db318cdd3e | ||
|
|
6870abc4fc | ||
|
|
e4f6006797 | ||
|
|
5c192575ce | ||
|
|
3e7adde638 | ||
|
|
fe9ef1e4bd | ||
|
|
75058ebf22 | ||
|
|
5cb52fa239 | ||
|
|
77654875e5 | ||
|
|
63f9f660a9 | ||
|
|
92d814b2f6 | ||
|
|
0d963b224f | ||
|
|
e9f28ff745 | ||
|
|
dbfcb431a8 | ||
|
|
1d2a2fcd9a | ||
|
|
af17501318 | ||
|
|
9e37f0d09e | ||
|
|
ef10bcd151 | ||
|
|
1fbd91ebf9 | ||
|
|
71116f785f | ||
|
|
84049a4542 | ||
|
|
aebe193136 | ||
|
|
e690f21e4e | ||
|
|
ff2f961ad7 | ||
|
|
ce6487f63e | ||
|
|
49d7d2e8c4 | ||
|
|
8fcf713541 | ||
|
|
90dd69c8ad | ||
|
|
a0b6c4993a | ||
|
|
293d86771a | ||
|
|
e8dc0f7434 | ||
|
|
2500fe7dda | ||
|
|
1ce93fd60e | ||
|
|
b6d95c71ce | ||
|
|
69e5a28ed3 | ||
|
|
28b2a2ba2b | ||
|
|
3d3322d0c9 | ||
|
|
6fb9379f92 | ||
|
|
645054a8c4 | ||
|
|
868d64ebb8 | ||
|
|
202531321d | ||
|
|
253e87e4a2 | ||
|
|
d4bf4e6a89 | ||
|
|
0748b3085e | ||
|
|
714bf84528 | ||
|
|
391ce6e91f | ||
|
|
42695c22d0 | ||
|
|
a8695edc8f | ||
|
|
71c0c06a78 | ||
|
|
5df1e653d9 | ||
|
|
7959acddd9 | ||
|
|
c2d971f20e | ||
|
|
adc77bb622 | ||
|
|
2b66100c47 | ||
|
|
759cdd5a6d | ||
|
|
8969f018a4 | ||
|
|
9915f85e8b | ||
|
|
94a9c639c7 | ||
|
|
067149725d | ||
|
|
ba5700e555 | ||
|
|
8dfc4cee20 | ||
|
|
2e3cf0b3c0 | ||
|
|
5b51842b54 | ||
|
|
846a576978 | ||
|
|
284819e718 | ||
|
|
f9bc244718 | ||
|
|
2c429e5bb1 | ||
|
|
b93ac7785c | ||
|
|
ef110e167c | ||
|
|
37a7fac128 | ||
|
|
1d569573da | ||
|
|
0d0fde9904 | ||
|
|
25b3c96f43 | ||
|
|
cb5047734b | ||
|
|
3a846a2d47 | ||
|
|
2388c74d84 | ||
|
|
c79d6cd609 | ||
|
|
9b04e11bfc | ||
|
|
4f8fd5957f | ||
|
|
7b817f388d | ||
|
|
2db806fe0d | ||
|
|
e80e29be6d | ||
|
|
70f0111f69 | ||
|
|
812efaab90 | ||
|
|
49cf84c4fe | ||
|
|
6b3788051f | ||
|
|
046e528cc2 | ||
|
|
29855ed1e6 | ||
|
|
e2be8bc2bc | ||
|
|
5ad497924c | ||
|
|
c9a7837b44 | ||
|
|
54bf7f9a59 | ||
|
|
bb6354e205 | ||
|
|
2a2741d761 | ||
|
|
c7f6e80ad0 | ||
|
|
f86d823dc3 | ||
|
|
d2ab59fef8 | ||
|
|
b92f53ece5 | ||
|
|
ef42c822e6 | ||
|
|
79df5ffc3c | ||
|
|
18781ed397 | ||
|
|
988e966df3 | ||
|
|
814ff562e9 | ||
|
|
86fd073ee6 | ||
|
|
662a5c4ac7 | ||
|
|
eadd2685df | ||
|
|
8691894175 | ||
|
|
cfb9a22e70 | ||
|
|
fb0fa7f799 | ||
|
|
59fc8c818d | ||
|
|
4044f4123c | ||
|
|
61f727fb96 | ||
|
|
5e667ed476 | ||
|
|
bd6dbd3edf | ||
|
|
bb35450c17 | ||
|
|
610980dd23 | ||
|
|
a9b0ec7d1d | ||
|
|
957cd578f7 | ||
|
|
a0ea33d671 | ||
|
|
bc32b40088 | ||
|
|
70fa3f8d25 | ||
|
|
bac50413f1 | ||
|
|
da662d1332 | ||
|
|
9f66059f52 | ||
|
|
dd4e410a32 | ||
|
|
8723fc56b2 | ||
|
|
436381de93 | ||
|
|
94d261b42d | ||
|
|
5a761b7ae3 | ||
|
|
3f29862478 | ||
|
|
08ff08e043 | ||
|
|
e574abbbba | ||
|
|
6495e3479e | ||
|
|
df73085fea | ||
|
|
6065d003e8 | ||
|
|
c268cd9abc | ||
|
|
342ddcfca0 | ||
|
|
73d28f0b27 | ||
|
|
f18562279c | ||
|
|
2ae03668c4 | ||
|
|
91f63c0b68 | ||
|
|
e932d8371f | ||
|
|
3fce1ffe8d | ||
|
|
fe7d3ef177 | ||
|
|
56348b1a12 | ||
|
|
cc3bdc2b57 | ||
|
|
d97a36af88 | ||
|
|
c5f02b769d | ||
|
|
81e3f1482b | ||
|
|
c168122ff5 | ||
|
|
f255d03057 | ||
|
|
60da498ed4 | ||
|
|
ae9da3b62b | ||
|
|
3c00fe6dbb | ||
|
|
5ca2c43aed | ||
|
|
0b6ecf705d | ||
|
|
3addebb66b | ||
|
|
ded58f25e3 | ||
|
|
b8dda491c7 | ||
|
|
13020874a9 | ||
|
|
3c0235b44b | ||
|
|
aeb0cb7353 | ||
|
|
49886620c4 |
@@ -9,13 +9,13 @@ charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{md,rst}]
|
||||
[**.{md,rst}]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[.git*]
|
||||
indent_style = tab
|
||||
|
||||
[*.*sh]
|
||||
[{**.*sh,test/run}]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
@@ -23,7 +23,7 @@ shell_variant = bash
|
||||
binary_next_line = true # like -bn
|
||||
switch_case_indent = true # like -ci
|
||||
space_redirects = true # like -sr
|
||||
keep_padding = true # like -kp
|
||||
keep_padding = false # like -kp
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
bats-test:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15, macos-11.0]
|
||||
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
|
||||
@@ -28,3 +28,18 @@ repos:
|
||||
# - id: forbid-crlf
|
||||
- id: remove-crlf
|
||||
exclude: ".bat$"
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: dot-sh
|
||||
name: Check .sh files against bash-it requirements
|
||||
entry: ./hooks/dot-sh.sh
|
||||
language: system
|
||||
files: "\\.sh$"
|
||||
types: [file]
|
||||
- id: dot-bash
|
||||
name: Check .bash files against bash-it requirements
|
||||
exclude: "test/test_helper.bash"
|
||||
entry: ./hooks/dot-bash.sh
|
||||
language: system
|
||||
files: "\\.bash$"
|
||||
types: [file]
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
# shellcheck shell=bash
|
||||
cite 'about-alias'
|
||||
about-alias 'pbcopy and pbpaste shortcuts to linux'
|
||||
about-alias 'xclip shortcuts'
|
||||
|
||||
case $OSTYPE in
|
||||
linux*)
|
||||
XCLIP=$(command -v xclip)
|
||||
[[ $XCLIP ]] && \
|
||||
alias pbcopy="$XCLIP -selection clipboard" && \
|
||||
alias pbpaste="$XCLIP -selection clipboard -o"
|
||||
;;
|
||||
esac
|
||||
alias pbcopy="xclip -selection clipboard"
|
||||
alias pbpaste="xclip -selection clipboard -o"
|
||||
|
||||
alias xcpy="xclip -selection clipboard"
|
||||
alias xpst="xclip -selection clipboard -o"
|
||||
# to use it just install xclip on your distribution and it would work like:
|
||||
# $ echo "hello" | pbcopy
|
||||
# $ pbpaste
|
||||
# $ echo "hello" | xcpy
|
||||
# $ xpst
|
||||
# hello
|
||||
|
||||
# very useful for things like:
|
||||
# cat ~/.ssh/id_rsa.pub | pbcopy
|
||||
# cat ~/.ssh/id_rsa.pub | xcpy
|
||||
# have fun!
|
||||
|
||||
18
aliases/available/dnf.aliases.bash
Normal file
18
aliases/available/dnf.aliases.bash
Normal file
@@ -0,0 +1,18 @@
|
||||
# shellcheck shell=bash
|
||||
cite 'about-alias'
|
||||
about-alias 'dnf aliases for fedora 22+ distros'
|
||||
|
||||
alias dnfl="dnf list" # List packages
|
||||
alias dnfli="dnf list installed" # List installed packages
|
||||
alias dnfgl="dnf grouplist" # List package groups
|
||||
alias dnfmc="dnf makecache" # Generate metadata cache
|
||||
alias dnfp="dnf info" # Show package information
|
||||
alias dnfs="dnf search" # Search package
|
||||
|
||||
alias dnfu="sudo dnf upgrade" # Upgrade package
|
||||
alias dnfi="sudo dnf install" # Install package
|
||||
alias dnfri='sudo dnf reinstall' # Reinstall package
|
||||
alias dnfgi="sudo dnf groupinstall" # Install package group
|
||||
alias dnfr="sudo dnf remove" # Remove package
|
||||
alias dnfgr="sudo dnf groupremove" # Remove package group
|
||||
alias dnfc="sudo dnf clean all" # Clean cache
|
||||
@@ -1,137 +1,198 @@
|
||||
# shellcheck shell=bash
|
||||
cite 'about-alias'
|
||||
about-alias 'common git abbreviations'
|
||||
|
||||
# Aliases
|
||||
alias gcl='git clone'
|
||||
alias ga='git add'
|
||||
alias grm='git rm'
|
||||
alias gap='git add -p'
|
||||
alias gall='git add -A'
|
||||
alias gf='git fetch --all --prune'
|
||||
alias gft='git fetch --all --prune --tags'
|
||||
alias gfv='git fetch --all --prune --verbose'
|
||||
alias gftv='git fetch --all --prune --tags --verbose'
|
||||
alias gus='git reset HEAD'
|
||||
alias gpristine='git reset --hard && git clean -dfx'
|
||||
alias gclean='git clean -fd'
|
||||
alias gm="git merge"
|
||||
alias gmv='git mv'
|
||||
alias g='git'
|
||||
alias get='git'
|
||||
alias gs='git status'
|
||||
alias gss='git status -s'
|
||||
alias gsu='git submodule update --init --recursive'
|
||||
alias gl='git pull'
|
||||
alias gpl='git pull'
|
||||
alias glum='git pull upstream master'
|
||||
alias gpr='git pull --rebase'
|
||||
alias gpp='git pull && git push'
|
||||
alias gup='git fetch && git rebase'
|
||||
alias gp='git push'
|
||||
alias gpd='git push --delete'
|
||||
alias gpo='git push origin HEAD'
|
||||
alias gpu='git push --set-upstream'
|
||||
alias gpuo='git push --set-upstream origin'
|
||||
alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)'
|
||||
alias gpom='git push origin master'
|
||||
alias gr='git remote'
|
||||
alias grv='git remote -v'
|
||||
alias gra='git remote add'
|
||||
alias grb='git rebase'
|
||||
alias grm='git rebase master'
|
||||
alias grmi='git rebase master -i'
|
||||
|
||||
# add
|
||||
alias ga='git add'
|
||||
alias gall='git add -A'
|
||||
alias gap='git add -p'
|
||||
|
||||
# branch
|
||||
alias gb='git branch'
|
||||
alias gbD='git branch -D'
|
||||
alias gba='git branch -a'
|
||||
alias gbd='git branch -d'
|
||||
alias gbm='git branch -m'
|
||||
alias gbt='git branch --track'
|
||||
alias gdel='git branch -D'
|
||||
|
||||
# for-each-ref
|
||||
alias gbc='git for-each-ref --format="%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)" refs/remotes/ --sort=authorname DESC' # FROM https://stackoverflow.com/a/58623139/10362396
|
||||
|
||||
# commit
|
||||
alias gc='git commit -v'
|
||||
alias gca='git commit -v -a'
|
||||
alias gcaa='git commit -a --amend -C HEAD' # Add uncommitted and unstaged changes to the last commit
|
||||
alias gcam='git commit -v -am'
|
||||
alias gcamd='git commit --amend'
|
||||
alias gcm='git commit -v -m'
|
||||
alias gci='git commit --interactive'
|
||||
alias gcsam='git commit -S -am'
|
||||
|
||||
# checkout
|
||||
alias gcb='git checkout -b'
|
||||
alias gco='git checkout'
|
||||
alias gcob='git checkout -b'
|
||||
alias gcobu='git checkout -b ${USER}/'
|
||||
alias gcom='git checkout master'
|
||||
alias gcpd='git checkout master; git pull; git branch -D'
|
||||
alias gct='git checkout --track'
|
||||
|
||||
# clone
|
||||
alias gcl='git clone'
|
||||
|
||||
# clean
|
||||
alias gclean='git clean -fd'
|
||||
|
||||
# cherry-pick
|
||||
alias gcp='git cherry-pick'
|
||||
alias gcpx='git cherry-pick -x'
|
||||
|
||||
# diff
|
||||
alias gd='git diff'
|
||||
alias gds='git diff --staged'
|
||||
alias gdt='git difftool'
|
||||
alias gdv='git diff -w "$@" | vim -R -'
|
||||
alias gc='git commit -v'
|
||||
alias gca='git commit -v -a'
|
||||
alias gcm='git commit -v -m'
|
||||
alias gcam="git commit -v -am"
|
||||
alias gci='git commit --interactive'
|
||||
alias gcamd='git commit --amend'
|
||||
alias gb='git branch'
|
||||
alias gba='git branch -a'
|
||||
# FROM https://stackoverflow.com/a/58623139/10362396
|
||||
alias gbc='git for-each-ref --format="%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)" refs/remotes/ --sort=authorname DESC'
|
||||
alias gbt='git branch --track'
|
||||
alias gbm='git branch -m'
|
||||
alias gbd='git branch -d'
|
||||
alias gbD='git branch -D'
|
||||
alias gcount='git shortlog -sn'
|
||||
alias gcp='git cherry-pick'
|
||||
alias gcpx='git cherry-pick -x'
|
||||
alias gco='git checkout'
|
||||
alias gcom='git checkout master'
|
||||
alias gcb='git checkout -b'
|
||||
alias gcob='git checkout -b'
|
||||
alias gcobu='git checkout -b ${USER}/'
|
||||
alias gct='git checkout --track'
|
||||
alias gcpd='git checkout master; git pull; git branch -D'
|
||||
alias gexport='git archive --format zip --output'
|
||||
alias gdel='git branch -D'
|
||||
alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master'
|
||||
alias gll='git log --graph --pretty=oneline --abbrev-commit'
|
||||
alias gg="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative"
|
||||
alias ggf="git log --graph --date=short --pretty=format:'%C(auto)%h %Cgreen%an%Creset %Cblue%cd%Creset %C(auto)%d %s'"
|
||||
alias ggs="gg --stat"
|
||||
alias gsh="git show"
|
||||
alias gsl="git shortlog -sn"
|
||||
alias gwc="git whatchanged"
|
||||
alias gt="git tag"
|
||||
alias gta="git tag -a"
|
||||
alias gtd="git tag -d"
|
||||
alias gtl="git tag -l"
|
||||
alias gpatch="git format-patch -1"
|
||||
# From http://blogs.atlassian.com/2014/10/advanced-git-aliases/
|
||||
# Show commits since last pull
|
||||
alias gnew="git log HEAD@{1}..HEAD@{0}"
|
||||
# Add uncommitted and unstaged changes to the last commit
|
||||
alias gcaa="git commit -a --amend -C HEAD"
|
||||
# Rebase with latest remote master
|
||||
alias gprom="git fetch origin master && git rebase origin/master && git update-ref refs/heads/master origin/master"
|
||||
alias gpf="git push --force"
|
||||
alias gpunch="git push --force-with-lease"
|
||||
alias ggui="git gui"
|
||||
alias gcsam="git commit -S -am"
|
||||
# Stash aliases
|
||||
alias gst="git stash"
|
||||
alias gstb="git stash branch"
|
||||
alias gstd="git stash drop"
|
||||
alias gstl="git stash list"
|
||||
# Push introduced in git v2.13.2
|
||||
alias gstpu="git stash push"
|
||||
alias gstpum="git stash push -m"
|
||||
# Save deprecated since git v2.16.0
|
||||
# - aliases now resolve to push
|
||||
alias gsts="git stash push"
|
||||
alias gstsm="git stash push -m"
|
||||
# Alias gstpo added for symmetry with gstpu (push)
|
||||
# - gstp remains as alias for pop due to long-standing usage
|
||||
alias gstpo="git stash pop"
|
||||
alias gstp="git stash pop"
|
||||
# Switch aliases - Requires git v2.23+
|
||||
alias gsw="git switch"
|
||||
alias gswm="git switch master"
|
||||
alias gswc="git switch --create"
|
||||
alias gswt="git switch --track"
|
||||
# Git home
|
||||
alias ghm='cd "$(git rev-parse --show-toplevel)"'
|
||||
if ! _command_exists gh; then
|
||||
alias gh='ghm'
|
||||
fi
|
||||
# Show untracked files
|
||||
alias gu='git ls-files . --exclude-standard --others'
|
||||
|
||||
# Git SVN
|
||||
alias gsr='git svn rebase'
|
||||
# archive
|
||||
alias gexport='git archive --format zip --output'
|
||||
|
||||
# fetch
|
||||
alias gf='git fetch --all --prune'
|
||||
alias gft='git fetch --all --prune --tags'
|
||||
alias gftv='git fetch --all --prune --tags --verbose'
|
||||
alias gfv='git fetch --all --prune --verbose'
|
||||
alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master'
|
||||
alias gup='git fetch && git rebase'
|
||||
|
||||
# log
|
||||
alias gg='git log --graph --pretty=format:'\''%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset'\'' --abbrev-commit --date=relative'
|
||||
alias ggf='git log --graph --date=short --pretty=format:'\''%C(auto)%h %Cgreen%an%Creset %Cblue%cd%Creset %C(auto)%d %s'\'''
|
||||
alias ggs='gg --stat'
|
||||
alias gll='git log --graph --pretty=oneline --abbrev-commit'
|
||||
alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/
|
||||
alias gwc='git whatchanged'
|
||||
|
||||
# ls-files
|
||||
alias gu='git ls-files . --exclude-standard --others' # Show untracked files
|
||||
alias glsut='gu'
|
||||
alias glsum='git diff --name-only --diff-filter=U' # Show unmerged (conflicted) files
|
||||
|
||||
# gui
|
||||
alias ggui='git gui'
|
||||
|
||||
# home
|
||||
alias ghm='cd "$(git rev-parse --show-toplevel)"' # Git home
|
||||
# appendage to ghm
|
||||
if ! _command_exists gh; then
|
||||
alias gh='ghm'
|
||||
fi
|
||||
|
||||
# merge
|
||||
alias gm='git merge'
|
||||
|
||||
# mv
|
||||
alias gmv='git mv'
|
||||
|
||||
# patch
|
||||
alias gpatch='git format-patch -1'
|
||||
|
||||
# push
|
||||
alias gp='git push'
|
||||
alias gpd='git push --delete'
|
||||
alias gpf='git push --force'
|
||||
alias gpo='git push origin HEAD'
|
||||
alias gpom='git push origin master'
|
||||
alias gpu='git push --set-upstream'
|
||||
alias gpunch='git push --force-with-lease'
|
||||
alias gpuo='git push --set-upstream origin'
|
||||
alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)'
|
||||
|
||||
# pull
|
||||
alias gl='git pull'
|
||||
alias glum='git pull upstream master'
|
||||
alias gpl='git pull'
|
||||
alias gpp='git pull && git push'
|
||||
alias gpr='git pull --rebase'
|
||||
|
||||
# remote
|
||||
alias gr='git remote'
|
||||
alias gra='git remote add'
|
||||
alias grv='git remote -v'
|
||||
|
||||
# rm
|
||||
alias grm='git rm'
|
||||
|
||||
# rebase
|
||||
alias grb='git rebase'
|
||||
alias grbc='git rebase --continue'
|
||||
alias grm='git rebase master'
|
||||
alias grmi='git rebase master -i'
|
||||
alias gprom='git fetch origin master && git rebase origin/master && git update-ref refs/heads/master origin/master' # Rebase with latest remote master
|
||||
|
||||
# reset
|
||||
alias gus='git reset HEAD'
|
||||
alias gpristine='git reset --hard && git clean -dfx'
|
||||
|
||||
# status
|
||||
alias gs='git status'
|
||||
alias gss='git status -s'
|
||||
|
||||
# shortlog
|
||||
alias gcount='git shortlog -sn'
|
||||
alias gsl='git shortlog -sn'
|
||||
|
||||
# show
|
||||
alias gsh='git show'
|
||||
|
||||
# svn
|
||||
alias gsd='git svn dcommit'
|
||||
alias gsr='git svn rebase' # Git SVN
|
||||
|
||||
# stash
|
||||
alias gst='git stash'
|
||||
alias gstb='git stash branch'
|
||||
alias gstd='git stash drop'
|
||||
alias gstl='git stash list'
|
||||
alias gstp='git stash pop' # kept due to long-standing usage
|
||||
alias gstpo='git stash pop' # recommended for it's symmetry with gstpu (push)
|
||||
|
||||
## 'stash push' introduced in git v2.13.2
|
||||
alias gstpu='git stash push'
|
||||
alias gstpum='git stash push -m'
|
||||
|
||||
## 'stash save' deprecated since git v2.16.0, alias is now push
|
||||
alias gsts='git stash push'
|
||||
alias gstsm='git stash push -m'
|
||||
|
||||
# submodules
|
||||
alias gsu='git submodule update --init --recursive'
|
||||
|
||||
# switch
|
||||
# these aliases requires git v2.23+
|
||||
alias gsw='git switch'
|
||||
alias gswc='git switch --create'
|
||||
alias gswm='git switch master'
|
||||
alias gswt='git switch --track'
|
||||
|
||||
# tag
|
||||
alias gt='git tag'
|
||||
alias gta='git tag -a'
|
||||
alias gtd='git tag -d'
|
||||
alias gtl='git tag -l'
|
||||
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
alias gtls="git tag -l | gsort -V"
|
||||
;;
|
||||
*)
|
||||
alias gtls='git tag -l | sort -V'
|
||||
;;
|
||||
darwin*)
|
||||
alias gtls="git tag -l | gsort -V"
|
||||
;;
|
||||
*)
|
||||
alias gtls='git tag -l | sort -V'
|
||||
;;
|
||||
esac
|
||||
|
||||
# functions
|
||||
function gdv() {
|
||||
git diff --ignore-all-space "$@" | vim -R -
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ function _set_pkg_aliases()
|
||||
alias kcgpan='kubectl get pods --all-namespaces'
|
||||
alias kcgdan='kubectl get deployments --all-namespaces'
|
||||
# launches a disposable netshoot pod in the k8s cluster
|
||||
alias kcnetshoot='kubectl run --generator=run-pod/v1 netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash'
|
||||
alias kcnetshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash'
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ alias nud='npm update'
|
||||
alias nr='npm run'
|
||||
alias nls='npm list --depth=0 2>/dev/null'
|
||||
alias nlsg='npm list -g --depth=0 2>/dev/null'
|
||||
alias nt='npm test'
|
||||
|
||||
# npx
|
||||
alias nx='npx'
|
||||
|
||||
@@ -3,13 +3,20 @@ about-alias 'systemd service'
|
||||
|
||||
case $OSTYPE in
|
||||
linux*)
|
||||
# Improve aliases by bringing the common root `sc|scd` + `sre` for action + `u` for user
|
||||
alias sc='systemctl'
|
||||
alias scr='systemctl daemon-reload'
|
||||
alias scu='systemctl --user'
|
||||
alias scur='systemctl --user daemon-reload'
|
||||
alias scdr='systemctl daemon-reload'
|
||||
alias scdru='systemctl --user daemon-reload'
|
||||
alias scr='systemctl restart'
|
||||
alias scru='systemctl --user restart'
|
||||
alias sce='systemctl stop'
|
||||
alias scue='systemctl --user stop'
|
||||
alias sceu='systemctl --user stop'
|
||||
alias scs='systemctl start'
|
||||
alias scus='systemctl --user start'
|
||||
alias scsu='systemctl --user start'
|
||||
# Keeping previous aliases for a non-breaking change.
|
||||
alias scue='sceu'
|
||||
alias scus='scsu'
|
||||
alias scur='scdru'
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# shellcheck shell=bash
|
||||
cite 'about-alias'
|
||||
about-alias 'vim abbreviations'
|
||||
|
||||
|
||||
176
bash_it.sh
176
bash_it.sh
@@ -3,18 +3,18 @@
|
||||
BASH_IT_LOG_PREFIX="core: main: "
|
||||
|
||||
# Only set $BASH_IT if it's not already set
|
||||
if [ -z "$BASH_IT" ];
|
||||
then
|
||||
# Setting $BASH to maintain backwards compatibility
|
||||
export BASH_IT=$BASH
|
||||
BASH="$(bash -c 'echo $BASH')"
|
||||
export BASH
|
||||
BASH_IT_OLD_BASH_SETUP=true
|
||||
if [ -z "$BASH_IT" ]; then
|
||||
# Setting $BASH to maintain backwards compatibility
|
||||
export BASH_IT=$BASH
|
||||
BASH="$(bash -c 'echo $BASH')"
|
||||
export BASH
|
||||
BASH_IT_OLD_BASH_SETUP=true
|
||||
fi
|
||||
|
||||
# Load composure first, so we support function metadata
|
||||
# shellcheck source=./lib/composure.bash
|
||||
source "${BASH_IT}/lib/composure.bash"
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
|
||||
|
||||
# We need to load logging module first as well in order to be able to log
|
||||
# shellcheck source=./lib/log.bash
|
||||
source "${BASH_IT}/lib/log.bash"
|
||||
@@ -23,132 +23,136 @@ source "${BASH_IT}/lib/log.bash"
|
||||
[ -z "$BASH_IT_OLD_BASH_SETUP" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!"
|
||||
|
||||
# For backwards compatibility, look in old BASH_THEME location
|
||||
if [ -z "$BASH_IT_THEME" ];
|
||||
then
|
||||
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
|
||||
export BASH_IT_THEME="$BASH_THEME";
|
||||
unset BASH_THEME;
|
||||
if [ -z "$BASH_IT_THEME" ]; then
|
||||
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
|
||||
export BASH_IT_THEME="$BASH_THEME"
|
||||
unset BASH_THEME
|
||||
fi
|
||||
|
||||
# support 'plumbing' metadata
|
||||
cite _about _param _example _group _author _version
|
||||
cite about-alias about-plugin about-completion
|
||||
|
||||
# libraries, but skip appearance (themes) for now
|
||||
_log_debug "Loading libraries(except appearance)..."
|
||||
LIB="${BASH_IT}/lib/*.bash"
|
||||
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
|
||||
for _bash_it_config_file in $LIB
|
||||
do
|
||||
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
|
||||
filename=${_bash_it_config_file##*/}
|
||||
filename=${filename%.bash}
|
||||
BASH_IT_LOG_PREFIX="lib: ${filename}: "
|
||||
_log_debug "Loading library file..."
|
||||
# shellcheck disable=SC1090
|
||||
source "$_bash_it_config_file"
|
||||
fi
|
||||
for _bash_it_config_file in $LIB; do
|
||||
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
|
||||
filename=${_bash_it_config_file##*/}
|
||||
filename=${filename%.bash}
|
||||
BASH_IT_LOG_PREFIX="lib: ${filename}: "
|
||||
_log_debug "Loading library file..."
|
||||
# shellcheck disable=SC1090
|
||||
source "$_bash_it_config_file"
|
||||
fi
|
||||
done
|
||||
|
||||
# Load vendors
|
||||
BASH_IT_LOG_PREFIX="vendor: "
|
||||
for _bash_it_vendor_init in "${BASH_IT}"/vendor/init.d/*.bash; do
|
||||
_log_debug "Loading \"$(basename "${_bash_it_vendor_init}" .bash)\"..."
|
||||
# shellcheck disable=SC1090
|
||||
source "${_bash_it_vendor_init}"
|
||||
done
|
||||
unset _bash_it_vendor_init
|
||||
|
||||
BASH_IT_LOG_PREFIX="core: main: "
|
||||
# Load the global "enabled" directory
|
||||
# "family" param is empty so that files get sources in glob order
|
||||
# shellcheck source=./scripts/reloader.bash
|
||||
source "${BASH_IT}/scripts/reloader.bash"
|
||||
|
||||
# Load enabled aliases, completion, plugins
|
||||
for file_type in "aliases" "plugins" "completion"
|
||||
do
|
||||
# shellcheck source=./scripts/reloader.bash
|
||||
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
|
||||
for file_type in "aliases" "plugins" "completion"; do
|
||||
# shellcheck source=./scripts/reloader.bash
|
||||
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
|
||||
done
|
||||
|
||||
# Load theme, if a theme was set
|
||||
if [[ ! -z "${BASH_IT_THEME}" ]]; then
|
||||
_log_debug "Loading \"${BASH_IT_THEME}\" theme..."
|
||||
# Load colors and helpers first so they can be used in base theme
|
||||
BASH_IT_LOG_PREFIX="themes: colors: "
|
||||
# shellcheck source=./themes/colors.theme.bash
|
||||
source "${BASH_IT}/themes/colors.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: githelpers: "
|
||||
# shellcheck source=./themes/githelpers.theme.bash
|
||||
source "${BASH_IT}/themes/githelpers.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: p4helpers: "
|
||||
# shellcheck source=./themes/p4helpers.theme.bash
|
||||
source "${BASH_IT}/themes/p4helpers.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: command_duration: "
|
||||
# shellcheck source=./themes/command_duration.theme.bash
|
||||
source "${BASH_IT}/themes/command_duration.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: base: "
|
||||
# shellcheck source=./themes/base.theme.bash
|
||||
source "${BASH_IT}/themes/base.theme.bash"
|
||||
if [[ -n "${BASH_IT_THEME}" ]]; then
|
||||
_log_debug "Loading \"${BASH_IT_THEME}\" theme..."
|
||||
# Load colors and helpers first so they can be used in base theme
|
||||
BASH_IT_LOG_PREFIX="themes: colors: "
|
||||
# shellcheck source=./themes/colors.theme.bash
|
||||
source "${BASH_IT}/themes/colors.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: githelpers: "
|
||||
# shellcheck source=./themes/githelpers.theme.bash
|
||||
source "${BASH_IT}/themes/githelpers.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: p4helpers: "
|
||||
# shellcheck source=./themes/p4helpers.theme.bash
|
||||
source "${BASH_IT}/themes/p4helpers.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: command_duration: "
|
||||
# shellcheck source=./themes/command_duration.theme.bash
|
||||
source "${BASH_IT}/themes/command_duration.theme.bash"
|
||||
BASH_IT_LOG_PREFIX="themes: base: "
|
||||
# shellcheck source=./themes/base.theme.bash
|
||||
source "${BASH_IT}/themes/base.theme.bash"
|
||||
|
||||
BASH_IT_LOG_PREFIX="lib: appearance: "
|
||||
# appearance (themes) now, after all dependencies
|
||||
# shellcheck source=./lib/appearance.bash
|
||||
source "$APPEARANCE_LIB"
|
||||
BASH_IT_LOG_PREFIX="lib: appearance: "
|
||||
# appearance (themes) now, after all dependencies
|
||||
# shellcheck source=./lib/appearance.bash
|
||||
source "$APPEARANCE_LIB"
|
||||
fi
|
||||
|
||||
BASH_IT_LOG_PREFIX="core: main: "
|
||||
_log_debug "Loading custom aliases, completion, plugins..."
|
||||
for file_type in "aliases" "completion" "plugins"
|
||||
do
|
||||
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]
|
||||
then
|
||||
BASH_IT_LOG_PREFIX="${file_type}: custom: "
|
||||
_log_debug "Loading component..."
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
|
||||
fi
|
||||
for file_type in "aliases" "completion" "plugins"; do
|
||||
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then
|
||||
BASH_IT_LOG_PREFIX="${file_type}: custom: "
|
||||
_log_debug "Loading component..."
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
|
||||
fi
|
||||
done
|
||||
|
||||
# Custom
|
||||
BASH_IT_LOG_PREFIX="core: main: "
|
||||
_log_debug "Loading general custom files..."
|
||||
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
|
||||
for _bash_it_config_file in $CUSTOM
|
||||
do
|
||||
if [ -e "${_bash_it_config_file}" ]; then
|
||||
filename=$(basename "${_bash_it_config_file}")
|
||||
filename=${filename%*.bash}
|
||||
BASH_IT_LOG_PREFIX="custom: $filename: "
|
||||
_log_debug "Loading custom file..."
|
||||
# shellcheck disable=SC1090
|
||||
source "$_bash_it_config_file"
|
||||
fi
|
||||
for _bash_it_config_file in $CUSTOM; do
|
||||
if [ -e "${_bash_it_config_file}" ]; then
|
||||
filename=$(basename "${_bash_it_config_file}")
|
||||
filename=${filename%*.bash}
|
||||
BASH_IT_LOG_PREFIX="custom: $filename: "
|
||||
_log_debug "Loading custom file..."
|
||||
# shellcheck disable=SC1090
|
||||
source "$_bash_it_config_file"
|
||||
fi
|
||||
done
|
||||
|
||||
unset _bash_it_config_file
|
||||
if [[ $PROMPT ]]; then
|
||||
export PS1="\[""$PROMPT""\]"
|
||||
export PS1="\[""$PROMPT""\]"
|
||||
fi
|
||||
|
||||
# Adding Support for other OSes
|
||||
PREVIEW="less"
|
||||
|
||||
if [ -s /usr/bin/gloobus-preview ]; then
|
||||
PREVIEW="gloobus-preview"
|
||||
PREVIEW="gloobus-preview"
|
||||
elif [ -s /Applications/Preview.app ]; then
|
||||
# shellcheck disable=SC2034
|
||||
PREVIEW="/Applications/Preview.app"
|
||||
# shellcheck disable=SC2034
|
||||
PREVIEW="/Applications/Preview.app"
|
||||
fi
|
||||
|
||||
# Load all the Jekyll stuff
|
||||
|
||||
if [ -e "$HOME/.jekyllconfig" ]
|
||||
then
|
||||
# shellcheck disable=SC1090
|
||||
. "$HOME/.jekyllconfig"
|
||||
if [ -e "$HOME/.jekyllconfig" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
. "$HOME/.jekyllconfig"
|
||||
fi
|
||||
|
||||
# BASH_IT_RELOAD_LEGACY is set.
|
||||
if ! command -v reload &>/dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
alias reload='source ~/.bash_profile'
|
||||
;;
|
||||
*)
|
||||
alias reload='source ~/.bashrc'
|
||||
;;
|
||||
esac
|
||||
if ! command -v reload &> /dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
alias reload='source ~/.bash_profile'
|
||||
;;
|
||||
*)
|
||||
alias reload='source ~/.bashrc'
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040
|
||||
|
||||
@@ -17,25 +17,91 @@
|
||||
# root directories
|
||||
#
|
||||
docs
|
||||
hooks
|
||||
|
||||
# root files
|
||||
#
|
||||
.gitattributes
|
||||
lint_clean_files.sh
|
||||
install.sh
|
||||
bash_it.sh
|
||||
|
||||
# themes
|
||||
#
|
||||
themes/agnoster
|
||||
themes/90210
|
||||
themes/powerline
|
||||
themes/barbuk
|
||||
themes/atomic
|
||||
themes/axin
|
||||
themes/base.theme.bash
|
||||
themes/bakke
|
||||
themes/binaryanomaly
|
||||
themes/bira
|
||||
themes/bobby
|
||||
themes/bobby-python
|
||||
themes/brainy
|
||||
themes/brunton
|
||||
themes/command_duration.theme.bash
|
||||
themes/modern
|
||||
|
||||
# plugins
|
||||
#
|
||||
plugins/available/basher.plugin.bash
|
||||
plugins/available/cmd-returned-notify.plugin.bash
|
||||
plugins/available/docker-machine.plugin.bash
|
||||
plugins/available/git.plugin.bash
|
||||
plugins/available/go.plugin.bash
|
||||
plugins/available/goenv.plugin.bash
|
||||
plugins/available/history.plugin.bash
|
||||
plugins/available/history-search.plugin.bash
|
||||
plugins/available/history-substring-search.plugin.bash
|
||||
plugins/available/xterm.plugin.bash
|
||||
|
||||
# completions
|
||||
#
|
||||
completion/available/apm.completion.bash
|
||||
completion/available/awless.completion.bash
|
||||
completion/available/brew.completion.bash
|
||||
completion/available/cargo.completion.bash
|
||||
completion/available/composer.completion.bash
|
||||
completion/available/conda.completion.bash
|
||||
completion/available/consul.completion.bash
|
||||
completion/available/django.completion.bash
|
||||
completion/available/docker.completion.bash
|
||||
completion/available/docker-machine.completion.bash
|
||||
completion/available/gcloud.completion.bash
|
||||
completion/available/gem.completion.bash
|
||||
completion/available/go.completion.bash
|
||||
completion/available/github-cli.completion.bash
|
||||
completion/available/helm.completion.bash
|
||||
completion/available/jungle.completion.bash
|
||||
completion/available/knife.completion.bash
|
||||
completion/available/kontena.completion.bash
|
||||
completion/available/kubectl.completion.bash
|
||||
completion/available/lerna.completion.bash
|
||||
completion/available/minikube.completion.bash
|
||||
completion/available/notify-send.completion.bash
|
||||
completion/available/npm.completion.bash
|
||||
completion/available/packer.completion.bash
|
||||
completion/available/pip.completion.bash
|
||||
completion/available/pip3.completion.bash
|
||||
completion/available/pipenv.completion.bash
|
||||
completion/available/pipx.completion.bash
|
||||
completion/available/rustup.completion.bash
|
||||
completion/available/vault.completion.bash
|
||||
completion/available/sdkman.completion.bash
|
||||
completion/available/vuejs.completion.bash
|
||||
|
||||
# aliases
|
||||
#
|
||||
aliases/available/dnf.aliases.bash
|
||||
aliases/available/vim.aliases.bash
|
||||
aliases/available/git.aliases.bash
|
||||
|
||||
# tests
|
||||
test/test_helper.bash
|
||||
|
||||
# vendor init files
|
||||
vendor/.gitattributes
|
||||
vendor/init.d
|
||||
|
||||
@@ -1,77 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# The MIT License (MIT)
|
||||
|
||||
# Copyright (c) 2015 Uğur "vigo" Özyılmazel
|
||||
|
||||
# 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.
|
||||
|
||||
# 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
|
||||
# shellcheck shell=bash
|
||||
about-completion "apm completion"
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT}"/vendor/github.com/vigo/apm-bash-completion/apm
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
[[ -x "$(which awless)" ]] && source <(awless completion bash)
|
||||
# shellcheck shell=bash
|
||||
if _command_exists awless; then
|
||||
# shellcheck disable=SC1090
|
||||
source <(awless completion bash)
|
||||
fi
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "brew completion"
|
||||
|
||||
# Load late to make sure `system` completion loads first
|
||||
# BASH_IT_LOAD_PRIORITY: 375
|
||||
|
||||
if [[ "$(uname -s)" != 'Darwin' ]] ; then
|
||||
_log_warning "unsupported operating system - only 'Darwin' is supported"
|
||||
return 0
|
||||
if [[ "$(uname -s)" != 'Darwin' ]]; then
|
||||
_log_warning "unsupported operating system - only 'Darwin' is supported"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Make sure brew is installed
|
||||
@@ -13,15 +15,18 @@ _command_exists brew || return 0
|
||||
|
||||
BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)}
|
||||
|
||||
if [[ -r "$BREW_PREFIX"/etc/bash_completion.d/brew ]] ; then
|
||||
source "$BREW_PREFIX"/etc/bash_completion.d/brew
|
||||
if [[ -r "$BREW_PREFIX"/etc/bash_completion.d/brew ]]; then
|
||||
# shellcheck disable=1090
|
||||
source "$BREW_PREFIX"/etc/bash_completion.d/brew
|
||||
|
||||
elif [[ -r "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]] ; then
|
||||
source "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh
|
||||
elif [[ -r "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]]; then
|
||||
# shellcheck disable=1090
|
||||
source "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh
|
||||
|
||||
elif [[ -f "$BREW_PREFIX"/completions/bash/brew ]] ; then
|
||||
# For the git-clone based installation, see here for more info:
|
||||
# https://github.com/Bash-it/bash-it/issues/1458
|
||||
# https://docs.brew.sh/Shell-Completion
|
||||
source "$BREW_PREFIX"/completions/bash/brew
|
||||
elif [[ -f "$BREW_PREFIX"/completions/bash/brew ]]; then
|
||||
# For the git-clone based installation, see here for more info:
|
||||
# https://github.com/Bash-it/bash-it/issues/1458
|
||||
# https://docs.brew.sh/Shell-Completion
|
||||
# shellcheck disable=1090
|
||||
source "$BREW_PREFIX"/completions/bash/brew
|
||||
fi
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck shell=bash
|
||||
# cargo (Rust package manager) completion
|
||||
|
||||
if _binary_exists rustup && _binary_exists cargo; then
|
||||
|
||||
@@ -1,133 +1,129 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "composer completion"
|
||||
|
||||
_composer()
|
||||
{
|
||||
local cur script coms opts com
|
||||
COMPREPLY=()
|
||||
_get_comp_words_by_ref -n : cur words
|
||||
function __composer_completion() {
|
||||
local cur 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
|
||||
|
||||
# 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"
|
||||
|
||||
# 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"
|
||||
;;
|
||||
|
||||
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
|
||||
|
||||
esac
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
|
||||
__ltrim_colon_completions "$cur"
|
||||
|
||||
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
|
||||
__ltrim_colon_completions "$cur"
|
||||
return 0
|
||||
fi
|
||||
|
||||
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"
|
||||
|
||||
# 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"
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${coms}" -- "${cur}"))
|
||||
__ltrim_colon_completions "$cur"
|
||||
|
||||
COMPREPLY=($(compgen -W "${coms}" -- ${cur}))
|
||||
__ltrim_colon_completions "$cur"
|
||||
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
complete -o default -F _composer composer
|
||||
complete -o default -F __composer_completion composer
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
which register-python-argcomplete > /dev/null \
|
||||
&& eval "$(register-python-argcomplete conda)" \
|
||||
|| echo "Please install argcomplete to use conda completion"
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "conda completion"
|
||||
|
||||
if _command_exists conda; then
|
||||
if _command_exists register-python-argcomplete; then
|
||||
eval "$(register-python-argcomplete conda)"
|
||||
else
|
||||
_log_warning "Argcomplete not found. Please run 'conda install argcomplete'"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
# bash completion support for Hashicorp consul
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "Hashicorp consul completion"
|
||||
|
||||
CONSUL_BIN=$(command -v consul 2>/dev/null)
|
||||
|
||||
if [[ -x "$CONSUL_BIN" ]]
|
||||
then
|
||||
complete -C "$CONSUL_BIN" consul
|
||||
if _command_exists consul; then
|
||||
complete -C "$(which consul)" consul
|
||||
fi
|
||||
|
||||
unset CONSUL_BIN
|
||||
|
||||
@@ -1,101 +1,4 @@
|
||||
# #########################################################################
|
||||
# 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.
|
||||
#
|
||||
# This file is licensed under the following license:
|
||||
# Copyright (c) Django Software Foundation and individual contributors.
|
||||
# All rights reserved.
|
||||
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
|
||||
# 2. 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.
|
||||
|
||||
# 3. Neither the name of Django 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.
|
||||
|
||||
|
||||
_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
|
||||
# shellcheck shell=bash
|
||||
about-completion "django completion"
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT}"/vendor/github.com/django/django/extras/django_bash_completion
|
||||
|
||||
@@ -1,431 +1,3 @@
|
||||
#
|
||||
# bash completion file for docker-machine commands
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Copyright (c) 2014 Docker, Inc
|
||||
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
# --- helper functions -------------------------------------------------------
|
||||
|
||||
_docker_machine_q() {
|
||||
docker-machine 2>/dev/null "$@"
|
||||
}
|
||||
|
||||
# suppresses trailing whitespace
|
||||
_docker_machine_nospace() {
|
||||
# compopt is not available in ancient bash versions (OSX)
|
||||
# so only call it if it's available
|
||||
type compopt &>/dev/null && compopt -o nospace
|
||||
}
|
||||
|
||||
_docker_machine_machines() {
|
||||
_docker_machine_q ls --format '{{.Name}}' "$@"
|
||||
}
|
||||
|
||||
_docker_machine_drivers() {
|
||||
local drivers=(
|
||||
amazonec2
|
||||
azure
|
||||
digitalocean
|
||||
exoscale
|
||||
generic
|
||||
google
|
||||
hyperv
|
||||
openstack
|
||||
rackspace
|
||||
softlayer
|
||||
virtualbox
|
||||
vmwarefusion
|
||||
vmwarevcloudair
|
||||
vmwarevsphere
|
||||
)
|
||||
echo "${drivers[@]}"
|
||||
}
|
||||
|
||||
_docker_machine_value_of_option() {
|
||||
local pattern="$1"
|
||||
for (( i=2; i < ${cword}; ++i)); do
|
||||
if [[ ${words[$i]} =~ ^($pattern)$ ]] ; then
|
||||
echo ${words[$i + 1]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Returns `key` if we are currently completing the value of a map option
|
||||
# (`key=value`) which matches the glob passed in as an argument.
|
||||
# This function is needed for key-specific argument completions.
|
||||
_docker_machine_map_key_of_current_option() {
|
||||
local glob="$1"
|
||||
|
||||
local key glob_pos
|
||||
if [ "$cur" = "=" ] ; then # key= case
|
||||
key="$prev"
|
||||
glob_pos=$((cword - 2))
|
||||
elif [[ $cur == *=* ]] ; then # key=value case (OSX)
|
||||
key=${cur%=*}
|
||||
glob_pos=$((cword - 1))
|
||||
elif [ "$prev" = "=" ] ; then
|
||||
key=${words[$cword - 2]} # key=value case
|
||||
glob_pos=$((cword - 3))
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
[ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
|
||||
|
||||
[[ ${words[$glob_pos]} == $glob ]] && echo "$key"
|
||||
}
|
||||
|
||||
# Finds the position of the first word that is neither option nor an option's argument.
|
||||
# If there are options that require arguments, you need to pass a glob describing
|
||||
# those options, e.g. "--option1|-o|--option2".
|
||||
# Use this function to restrict completions to exact positions after the options.
|
||||
_docker_machine_pos_first_nonflag() {
|
||||
local argument_flags=$1
|
||||
|
||||
local counter=$((${subcommand_pos:-${command_pos}} + 1))
|
||||
while [ "$counter" -le "$cword" ]; do
|
||||
if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
|
||||
(( counter++ ))
|
||||
# eat "=" in case of --option=arg syntax
|
||||
[ "${words[$counter]}" = "=" ] && (( counter++ ))
|
||||
else
|
||||
case "${words[$counter]}" in
|
||||
-*)
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Bash splits words at "=", retaining "=" as a word, examples:
|
||||
# "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
|
||||
while [ "${words[$counter + 1]}" = "=" ] ; do
|
||||
counter=$(( counter + 2))
|
||||
done
|
||||
|
||||
(( counter++ ))
|
||||
done
|
||||
|
||||
echo $counter
|
||||
}
|
||||
# --- completion functions ---------------------------------------------------
|
||||
|
||||
_docker_machine_active() {
|
||||
case "${prev}" in
|
||||
--timeout|-t)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help --timeout -t" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_config() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help --swarm" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_create() {
|
||||
case "${prev}" in
|
||||
--driver|-d)
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_drivers)" -- "${cur}"))
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
# driver specific options are only included in help output if --driver is given,
|
||||
# so we have to pass that option when calling docker-machine to harvest options.
|
||||
local driver="$(_docker_machine_value_of_option '--driver|-d')"
|
||||
local parsed_options="$(_docker_machine_q create ${driver:+--driver $driver} --help | grep '^ -' | sed 's/^ //; s/[^a-z0-9-].*$//')"
|
||||
if [[ ${cur} == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "${parsed_options} -d --help" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_env() {
|
||||
case "${prev}" in
|
||||
--shell)
|
||||
COMPREPLY=($(compgen -W "cmd emacs fish powershell tcsh" -- "${cur}"))
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help --no-proxy --shell --swarm --unset -u" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
# See docker-machine-wrapper.bash for the use command
|
||||
_docker_machine_use() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help --swarm --unset" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_inspect() {
|
||||
case "${prev}" in
|
||||
--format|-f)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--format -f --help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_ip() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_kill() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_ls() {
|
||||
local key=$(_docker_machine_map_key_of_current_option '--filter')
|
||||
case "$key" in
|
||||
driver)
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_drivers)" -- "${cur##*=}"))
|
||||
return
|
||||
;;
|
||||
state)
|
||||
COMPREPLY=($(compgen -W "Error Paused Running Saved Starting Stopped Stopping" -- "${cur##*=}"))
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "${prev}" in
|
||||
--filter)
|
||||
COMPREPLY=($(compgen -W "driver label name state swarm" -S= -- "${cur}"))
|
||||
_docker_machine_nospace
|
||||
return
|
||||
;;
|
||||
--format|-f|--timeout|-t)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--filter --format -f --help --quiet -q --timeout -t" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_mount() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help --unmount -u" -- "${cur}"))
|
||||
else
|
||||
local pos=$(_docker_machine_pos_first_nonflag)
|
||||
if [ "$cword" -eq "$pos" ]; then
|
||||
# We can't complete remote filesystems. All we can do here is to complete the machine.
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -S: -- "${cur}"))
|
||||
_docker_machine_nospace
|
||||
elif [ "$cword" -eq "$((pos + 1))" ]; then
|
||||
_filedir -d
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_provision() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_regenerate_certs() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--client-certs --force -f --help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_restart() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_rm() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--force -f --help -y" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_ssh() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_scp() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--delta -d --help --quiet -q --recursive -r" -- "${cur}"))
|
||||
else
|
||||
_filedir
|
||||
# It would be really nice to ssh to the machine and ls to complete
|
||||
# remote files.
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines | sed 's/$/:/')" -- "${cur}") "${COMPREPLY[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_start() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Stopped)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_status() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_stop() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_upgrade() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_url() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}"))
|
||||
fi
|
||||
}
|
||||
|
||||
_docker_machine_version() {
|
||||
if [[ "${cur}" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${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 mount provision 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 command_pos=0
|
||||
|
||||
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}
|
||||
command_pos=$i
|
||||
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 docker-machine.exe
|
||||
# shellcheck shell=bash
|
||||
_log_warning '"docker-machine" is now deprecated, and as such the bash completion for it is also deprecated.
|
||||
Please disable this completion.'
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "docker completion"
|
||||
|
||||
# Make sure docker is installed
|
||||
_command_exists docker || return
|
||||
|
||||
# Don't handle completion if it's already managed
|
||||
complete -p docker &>/dev/null && return
|
||||
_completion_exists docker && return
|
||||
|
||||
_docker_bash_completion_paths=(
|
||||
# MacOS
|
||||
'/Applications/Docker.app/Contents/Resources/etc/docker.bash-completion'
|
||||
# Linux
|
||||
'/usr/share/bash-completion/completions/docker'
|
||||
# MacOS
|
||||
'/Applications/Docker.app/Contents/Resources/etc/docker.bash-completion'
|
||||
# Linux
|
||||
'/usr/share/bash-completion/completions/docker'
|
||||
)
|
||||
|
||||
for fn in "${_docker_bash_completion_paths[@]}" ; do
|
||||
if [ -r "$fn" ] ; then
|
||||
source "$fn"
|
||||
break
|
||||
fi
|
||||
for fn in "${_docker_bash_completion_paths[@]}"; do
|
||||
if [ -r "$fn" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
source "$fn"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
_log_error 'Bash completion for "drush" is now deprecated, as it used code with incompatible license.
|
||||
_log_warning 'Bash completion for "drush" is now deprecated, as it used code with incompatible license.
|
||||
Please disable this completion and use the instructions from "drush" developers instead.'
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#/usr/bin/env bash
|
||||
# Bash completion for Google Cloud SDK
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "Google Cloud SDK completion"
|
||||
|
||||
if which gcloud >/dev/null 2>&1; then
|
||||
GOOGLE_SDK_ROOT=${GOOGLE_SDK_ROOT:-$(gcloud info --format="value(installation.sdk_root)")}
|
||||
for i in $(ls ${GOOGLE_SDK_ROOT}/*.bash.inc); do
|
||||
source $i
|
||||
done
|
||||
if _command_exists gcloud; then
|
||||
# get install path
|
||||
GOOGLE_SDK_ROOT=${GOOGLE_SDK_ROOT:-$(gcloud info --format="value(installation.sdk_root)")}
|
||||
|
||||
# source all the bash completion file that are available
|
||||
for i in "${GOOGLE_SDK_ROOT}"/*.bash.inc; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$i"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -1,41 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
# Completion for gem
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "gem completion"
|
||||
|
||||
_installcomp() {
|
||||
if [ -z "$REMOTE_GEMS" ]
|
||||
then
|
||||
REMOTE_GEMS=( $(gem list --remote --no-versions | tr '\n' ' ') )
|
||||
fi
|
||||
__gem_completion() {
|
||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||
local prev=${COMP_WORDS[COMP_CWORD - 1]}
|
||||
case $prev in
|
||||
install)
|
||||
# list the remote gems and add to completion
|
||||
if [ -z "$REMOTE_GEMS" ]; then
|
||||
read -r -a REMOTE_GEMS <<< "$(gem list --remote --no-versions | sed 's/\*\*\* REMOTE GEMS \*\*\*//' | tr '\n' ' ')"
|
||||
fi
|
||||
|
||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||
COMPREPLY=( $(compgen -W "${REMOTE_GEMS[*]}" -- $cur) )
|
||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${REMOTE_GEMS[*]}" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
uninstall)
|
||||
# list all local installed gems and add to completion
|
||||
read -r -a LOCAL_GEMS <<< "$(gem list --no-versions | sed 's/\*\*\* LOCAL GEMS \*\*\*//' | tr '\n' ' ')"
|
||||
|
||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${LOCAL_GEMS[*]}" -- "$cur"))
|
||||
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)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${commands[*]}" -- "$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
|
||||
complete -F __gem_completion gem
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "GitHub CLI completion"
|
||||
|
||||
if _binary_exists gh; then
|
||||
if _command_exists brew; then
|
||||
_log_warning "You don't need github-cli completion enabled if you have system completion enabled"
|
||||
fi
|
||||
eval "$(gh completion --shell=bash)"
|
||||
# If gh already completed, stop
|
||||
_completion_exists gh && return
|
||||
eval "$(gh completion --shell=bash)"
|
||||
fi
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
about-completion "completion for go command using gocomplete"
|
||||
|
||||
# bash completion for go tool
|
||||
# https://github.com/posener/complete
|
||||
# https://pkg.go.dev/github.com/posener/complete?tab=doc
|
||||
|
||||
# Install gocomplete:
|
||||
# go get -u github.com/posener/complete/gocomplete
|
||||
# gocomplete -install
|
||||
|
||||
if _command_exists gocomplete && _command_exists go ; then
|
||||
complete -C "${GOBIN}"/gocomplete go
|
||||
# Test `go version` because goenv creates shim scripts that will be found in PATH
|
||||
# but do not always resolve to a working install.
|
||||
if _command_exists go && go version &> /dev/null; then
|
||||
# Same idea here, but no need to test a subcommand
|
||||
if _command_exists gocomplete && gocomplete &> /dev/null; then
|
||||
# finally, apply completion
|
||||
complete -C gocomplete go
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "helm (Kubernetes Package Manager) completion"
|
||||
|
||||
# helm (Kubernetes Package Manager) completion
|
||||
|
||||
if command -v helm &>/dev/null
|
||||
then
|
||||
eval "$(helm completion bash)"
|
||||
if _command_exists helm; then
|
||||
eval "$(helm completion bash)"
|
||||
fi
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
_log_error 'Bash completion for "homesick" is now deprecated, as it used unlicensed code.
|
||||
_log_warning 'Bash completion for "homesick" is now deprecated, as it used unlicensed code.
|
||||
Please disable this completion and use the instructions from "homesick" bash completion developers instead.'
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
[[ -x "$(which jungle)" ]] && eval "$(_JUNGLE_COMPLETE=source jungle)"
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "jungle(AWS cli tool) completion"
|
||||
|
||||
if _command_exists jungle; then
|
||||
eval "$(_JUNGLE_COMPLETE=source jungle)"
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Published originally as public domain code at https://github.com/wk8/knife-bash-autocomplete
|
||||
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
which kontena > /dev/null && . "$( kontena whoami --bash-completion-path )"
|
||||
# shellcheck shell=bash
|
||||
if _command_exists kontena; then
|
||||
# shellcheck disable=SC1090
|
||||
source "$(kontena whoami --bash-completion-path)"
|
||||
fi
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "kubectl (Kubernetes CLI) completion"
|
||||
|
||||
# kubectl (Kubernetes CLI) completion
|
||||
|
||||
if command -v kubectl &>/dev/null
|
||||
then
|
||||
eval "$(kubectl completion bash)"
|
||||
if _binary_exists kubectl; then
|
||||
eval "$(kubectl completion bash)"
|
||||
fi
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
#!/bin/bash
|
||||
# Lerna autocompletion.
|
||||
function _lerna_completions() {
|
||||
local cur compls
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "lerna(javascript project manager tool) completion"
|
||||
|
||||
# The currently-being-completed word.
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
function __lerna_completion() {
|
||||
local cur compls
|
||||
|
||||
# Options
|
||||
compls="add bootstrap changed clean create diff exec \
|
||||
import init link list publish run version \
|
||||
--loglevel --concurrency --reject-cycles \
|
||||
--progress --sort --no-sort --help \
|
||||
--version"
|
||||
# The currently-being-completed word.
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
# Tell complete what stuff to show.
|
||||
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
|
||||
# Options
|
||||
compls="add bootstrap changed clean create diff exec \
|
||||
import init link list publish run version \
|
||||
--loglevel --concurrency --reject-cycles \
|
||||
--progress --sort --no-sort --help \
|
||||
--version"
|
||||
|
||||
# Tell complete what stuff to show.
|
||||
# shellcheck disable=2207
|
||||
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
|
||||
}
|
||||
complete -o default -F _lerna_completions lerna
|
||||
complete -o default -F __lerna_completion lerna
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck shell=bash
|
||||
# minikube (Local Kubernetes) completion
|
||||
|
||||
if command -v minikube &>/dev/null
|
||||
then
|
||||
eval "$(minikube completion bash)"
|
||||
if _command_exists minikube; then
|
||||
eval "$(minikube completion bash)"
|
||||
fi
|
||||
|
||||
19
completion/available/notify-send.completion.bash
Normal file
19
completion/available/notify-send.completion.bash
Normal file
@@ -0,0 +1,19 @@
|
||||
# shellcheck shell=bash
|
||||
|
||||
function __notify-send_completions() {
|
||||
local curr=$(_get_cword)
|
||||
local prev=$(_get_pword)
|
||||
|
||||
case $prev in
|
||||
-u | --urgency)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "low normal critical" -- "$curr"))
|
||||
;;
|
||||
*)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-? --help -u --urgency -t --expire-time -a --app-name -i --icon -c --category -h --hint -v --version" -- "$curr"))
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
complete -F __notify-send_completions notify-send
|
||||
@@ -1,9 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "npm (Node Package Manager) completion"
|
||||
|
||||
# npm (Node Package Manager) completion
|
||||
# https://docs.npmjs.com/cli/completion
|
||||
|
||||
if command -v npm &>/dev/null
|
||||
then
|
||||
eval "$(npm completion)"
|
||||
if _command_exists npm; then
|
||||
eval "$(npm completion)"
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "packer completion"
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# shellcheck shell=bash
|
||||
|
||||
# https://pip.pypa.io/en/stable/user_guide/#command-completion
|
||||
# Of course, you should first install the pip, say on Debian:
|
||||
# Of course, you should first install pip, say on Debian:
|
||||
# sudo apt-get install python-pip
|
||||
# sudo apt-get install python3-pip
|
||||
# If the pip package is installed within virtual environments, say, python managed by pyenv,
|
||||
# you should first initilization the corresponding environment.
|
||||
# So that the pip/pip3 is in system's path.
|
||||
if command -v pip >/dev/null; then
|
||||
eval "$(pip completion --bash)"
|
||||
# you should first initialize the corresponding environment.
|
||||
# So that pip is in the system's path.
|
||||
if _command_exists pip; then
|
||||
eval "$(pip completion --bash)"
|
||||
fi
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# shellcheck shell=bash
|
||||
|
||||
# https://pip.pypa.io/en/stable/user_guide/#command-completion
|
||||
# Of course, you should first install the pip, say on Debian:
|
||||
# sudo apt-get install python-pip
|
||||
# Of course, you should first install pip, say on Debian:
|
||||
# sudo apt-get install python3-pip
|
||||
# If the pip package is installed within virtual environments, say, python managed by pyenv,
|
||||
# you should first initilization the corresponding environment.
|
||||
# So that the pip/pip3 is in system's path.
|
||||
if command -v pip3 >/dev/null; then
|
||||
eval "$(pip3 completion --bash)"
|
||||
# you should first initialize the corresponding environment.
|
||||
# So that pip3 is in the system's path.
|
||||
if _command_exists pip3; then
|
||||
eval "$(pip3 completion --bash)"
|
||||
fi
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
[[ -x "$(which pipenv)" ]] && eval "$(pipenv --completion)"
|
||||
# shellcheck shell=bash
|
||||
if _command_exists pipenv; then
|
||||
eval "$(pipenv --completion)"
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# pipx completion
|
||||
|
||||
if _command_exists register-python-argcomplete && _command_exists pipx; then
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
# rustup (Rust toolchain installer) completion
|
||||
|
||||
|
||||
@@ -1,71 +1,83 @@
|
||||
_sdkman_complete()
|
||||
{
|
||||
local CANDIDATES
|
||||
local CANDIDATE_VERSIONS
|
||||
# shellcheck shell=bash
|
||||
_sdkman_complete() {
|
||||
local CANDIDATES
|
||||
local CANDIDATE_VERSIONS
|
||||
|
||||
COMPREPLY=()
|
||||
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
|
||||
"uninstall" | "rm" | "use" | "default" )
|
||||
_sdkman_candidate_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
"install")
|
||||
_sdkman_candidate_not_installed_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||
mapfile -t COMPREPLY < <(compgen -W "install uninstall rm list ls use default home env current upgrade ug version broadcast help offline selfupdate update flush" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
elif [ "$COMP_CWORD" -eq 2 ]; then
|
||||
case "${COMP_WORDS[COMP_CWORD - 1]}" in
|
||||
"install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug")
|
||||
CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ')
|
||||
mapfile -t COMPREPLY < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
;;
|
||||
"env")
|
||||
mapfile -t COMPREPLY < <(compgen -W "init" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
;;
|
||||
"offline")
|
||||
mapfile -t COMPREPLY < <(compgen -W "enable disable" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
;;
|
||||
"selfupdate")
|
||||
mapfile -t COMPREPLY < <(compgen -W "force" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
;;
|
||||
"flush")
|
||||
mapfile -t COMPREPLY < <(compgen -W "archives tmp broadcast version" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
;;
|
||||
*) ;;
|
||||
|
||||
return 0
|
||||
esac
|
||||
elif [ "$COMP_CWORD" -eq 3 ]; then
|
||||
case "${COMP_WORDS[COMP_CWORD - 2]}" in
|
||||
"uninstall" | "rm" | "use" | "u" | "default" | "d" | "home" | "h")
|
||||
_sdkman_candidate_local_versions "${COMP_WORDS[COMP_CWORD - 1]}"
|
||||
mapfile -t COMPREPLY < <(compgen -W "$CANDIDATE_VERSIONS" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
;;
|
||||
"install" | "i")
|
||||
_sdkman_candidate_all_versions "${COMP_WORDS[COMP_CWORD - 1]}"
|
||||
mapfile -t COMPREPLY < <(compgen -W "$CANDIDATE_VERSIONS" -- "${COMP_WORDS[COMP_CWORD]}")
|
||||
;;
|
||||
*) ;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_sdkman_candidate_versions(){
|
||||
_sdkman_candidate_local_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
|
||||
CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1")
|
||||
|
||||
}
|
||||
|
||||
_sdkman_candidate_not_installed_versions(){
|
||||
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions $1)
|
||||
if [ "$SDKMAN_OFFLINE_MODE" = "false" ]; then
|
||||
CANDIDATE_ONLINE_VERSIONS="$(__sdkman_list_versions $1 | grep " " | grep "\." | cut -c 6-)"
|
||||
CANDIDATE_VERSIONS="$(echo $CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS | tr ' ' '\n' | sort | uniq -u) "
|
||||
fi
|
||||
_sdkman_candidate_all_versions() {
|
||||
|
||||
candidate="$1"
|
||||
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate")
|
||||
if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then
|
||||
CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS
|
||||
else
|
||||
# sdkman has a specific output format for Java candidate since
|
||||
# there are multiple vendors and builds.
|
||||
if [ "$candidate" = "java" ]; then
|
||||
CANDIDATE_ONLINE_VERSIONS="$(__sdkman_list_versions "$candidate" | grep " " | grep "\." | cut -c 62-)"
|
||||
else
|
||||
CANDIDATE_ONLINE_VERSIONS="$(__sdkman_list_versions "$candidate" | grep " " | grep "\." | cut -c 6-)"
|
||||
fi
|
||||
# the last grep is used to filter out sdkman flags, such as:
|
||||
# "+" - local version
|
||||
# "*" - installed
|
||||
# ">" - currently in use
|
||||
CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort | uniq -u) "
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
__sdkman_cleanup_local_versions(){
|
||||
__sdkman_cleanup_local_versions() {
|
||||
|
||||
__sdkman_build_version_csv $1 | tr ',' ' '
|
||||
__sdkman_build_version_csv "$1" | tr ',' ' '
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
_log_error 'Bash completion for "todo.txt-cli" is now deprecated, as it used code with incompatible license.
|
||||
_log_warning 'Bash completion for "todo.txt-cli" is now deprecated, as it used code with incompatible license.
|
||||
Please disable this completion and use the instructions from "todo.txt-cli" developers instead.'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "vault completion"
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
_log_error 'Bash completion for "virsh" is now deprecated, as it used code with incompatible license.
|
||||
_log_warning 'Bash completion for "virsh" is now deprecated, as it used code with incompatible license.
|
||||
Please disable this completion and use the instructions from "virsh" developers instead.'
|
||||
|
||||
@@ -1,15 +1,59 @@
|
||||
#!/usr/bin/bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
if command -v vue > /dev/null; then
|
||||
__vuejs_completion() {
|
||||
local OPTS=("--version --help create add invoke inspect serve build ui init config upgrade info")
|
||||
COMPREPLY=()
|
||||
for _opt_ in ${OPTS[@]}; do
|
||||
if [[ "$_opt_" == "$2"* ]]; then
|
||||
COMPREPLY+=("$_opt_")
|
||||
fi
|
||||
done
|
||||
}
|
||||
__vuejs_completion() {
|
||||
local prev=$(_get_pword)
|
||||
local curr=$(_get_cword)
|
||||
|
||||
complete -F __vuejs_completion vue
|
||||
fi
|
||||
case $prev in
|
||||
create)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-p -d -i -m -r -g -n -f -c -x -b -h --help --preset --default --inilinePreset --packageManager --registry --git --no-git --force --merge --clone --proxy --bare --skipGetStarted" -- "$curr"))
|
||||
;;
|
||||
add | invoke)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "--registry -h --help" -- "$curr"))
|
||||
;;
|
||||
inspect)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-v --help --verbose --mode --rule --plugin --plugins --rules" -- "$curr"))
|
||||
;;
|
||||
serve)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-o -h --help --open -c --copy -p --port" -- "$curr"))
|
||||
;;
|
||||
build)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-t --target -n --name -d --dest -h --help" -- "$curr"))
|
||||
;;
|
||||
ui)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-H --host -p --port -D --dev --quiet --headless -h --help" -- "$curr"))
|
||||
;;
|
||||
init)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-c --clone --offline -h --help" -- "$curr"))
|
||||
;;
|
||||
config)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-g --get -s --set -d --delete -e --edit --json -h --help" -- "$curr"))
|
||||
;;
|
||||
outdated)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "--next -h --help" -- "$curr"))
|
||||
;;
|
||||
upgrade)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-t --to -f --from -r --registry --all --next -h --help" -- "$curr"))
|
||||
;;
|
||||
migrate)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-f --from -h --help" -- "$curr"))
|
||||
;;
|
||||
*)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "-h --help -v --version create add invoke inspect serve build ui init config outdated upgrade migrate info" -- "$curr"))
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
complete -F __vuejs_completion vue
|
||||
|
||||
@@ -10,11 +10,6 @@ Issues
|
||||
------
|
||||
|
||||
|
||||
* When opening a new issue in the issue tracker, please include information about which *Operating System* you're using, and which version of *Bash*.
|
||||
* In many cases, it also makes sense to show which Bash-it plugins you are using.
|
||||
This information can be obtained using ``bash-it show plugins``.
|
||||
* If the issue happens while loading Bash-it, please also include your ``~/.bash_profile`` or ``~/.bashrc`` file,
|
||||
as well as the install location of Bash-it (default should be ``~/.bash_it``\ ).
|
||||
* When reporting a bug or requesting a new feature, consider providing a Pull Request that fixes the issue or can be used as a starting point for the new feature.
|
||||
Don't be afraid, most things aren't that complex...
|
||||
|
||||
@@ -42,6 +37,8 @@ Code Style
|
||||
* When changing existing files, consider also adding them into `clean_files.txt` and fixing the linting errors that arise. See :ref:`linting_your_changes` for more information.
|
||||
* Indentation is using tabs, not spaces. Most of the code is indented with 2 spaces, some with 4 spaced tabs. Please try to stick to tabs.
|
||||
If you're using an editor that supports `EditorConfig <http://EditorConfig.org>`_\ , the editor should automatically use the settings defined in Bash-it's `.editorconfig file <.editorconfig>`_.
|
||||
* Prefer to invoke commands directly using the ``command`` shell builtin. This way, your code
|
||||
will always execute the command you wanted and not an alias/function that overrides the name of the command. (For example, use ``command rm`` instead of ``rm``)
|
||||
* When creating new functions, please use a dash ("-") to separate the words of the function's name, e.g. ``my-new-function``.
|
||||
Don't use underscores, e.g. ``my_new_function``.
|
||||
* Internal functions that aren't to be used by the end user should start with an underscore, e.g. ``_my-new-internal-function``.
|
||||
@@ -59,8 +56,8 @@ Unit Tests
|
||||
When adding features or making changes/fixes, please run our growing unit test suite to ensure that you did not break existing functionality.
|
||||
The test suite does not cover all aspects of Bash-it, but please run it anyway to verify that you did not introduce any regression issues.
|
||||
|
||||
Any code pushed to GitHub as part of a Pull Request will automatically trigger a continuous integration build on `Travis CI <https://travis-ci.org/Bash-it/bash-it>`_\ , where the test suite is run on both Linux and macOS.
|
||||
The Pull Request will then show the result of the Travis build, indicating whether all tests ran fine, or whether there were issues.
|
||||
Any code pushed to GitHub as part of a Pull Request will automatically trigger a continuous integration build on `GitHub Actions <https://github.com/Bash-it/bash-it/actions>`_\ , where the test suite is run on both Linux and macOS.
|
||||
The Pull Request will then show the result of the CI build, indicating whether all tests ran fine, or whether there were issues.
|
||||
Please pay attention to this, Pull Requests with build issues will not be merged.
|
||||
|
||||
Adding new functionality or changing existing functionality is a good opportunity to increase Bash-it's test coverage.
|
||||
|
||||
@@ -37,8 +37,12 @@ General Load Order
|
||||
The main ``bash_it.sh`` script loads the frameworks individual components in the following order:
|
||||
|
||||
|
||||
* ``lib/composure.bash``
|
||||
* Files in ``lib`` with the exception of ``appearance.bash`` - this means that ``composure.bash`` is loaded again here (possible improvement?)
|
||||
|
||||
|
||||
* ``vendor/github.com/erichs/composure/composure.sh``
|
||||
* ``lib/log.bash``
|
||||
* ``vendor/init.d/*.bash``
|
||||
* Files in ``lib`` with the exception of ``appearance.bash`` - this means that ``log.bash`` is loaded again here (possible improvement?)
|
||||
* Enabled ``aliases``
|
||||
* Enabled ``plugins``
|
||||
* Enabled ``completions``
|
||||
@@ -78,6 +82,65 @@ Having the order based on a numeric priority in a common directory allows for mo
|
||||
|
||||
These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well.
|
||||
|
||||
Working with vendored libs
|
||||
--------------------------
|
||||
|
||||
Vendored libs are external libraries, meaning source code not maintained by Bash-it
|
||||
developers.
|
||||
They are ``git subtrees`` curated in the ``vendor/`` folder. To ease the work with git
|
||||
vendored libs as subtrees we use the `git-vendor <https://github.com/Tyrben/git-vendor>`_ tool.
|
||||
The `original repo <https://github.com/brettlangdon/git-vendor>`_ for git vendor is
|
||||
unmaintained so for now we are recommending Tyrben's fork.
|
||||
|
||||
For more information on ``git vendor`` there are a short `usage description <https://github.com/Tyrben/git-vendor#usage>`_
|
||||
in the repositories ``README`` file and a website for the original repository has a `manual page <https://brettlangdon.github.io/git-vendor/>`_ which is also included in both
|
||||
repositories.
|
||||
|
||||
To support a flexible loading of external libraries, a file unique to the vendored
|
||||
library must be placed in ``vendor/init.d/`` with the ``.bash`` extension.
|
||||
|
||||
Rebasing a feature branch with an added/updated vendored library
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
If your feature branch with a newly added/updated vendored lib has fallen behind master
|
||||
you might need to rebase it before creating a PR. However rebasing with dangling
|
||||
subtree commits can cause problems.
|
||||
The following rebase strategy will pause the rebase at the point where you added a
|
||||
subtree and let you add it again before continuing the rebasing.
|
||||
|
||||
::
|
||||
|
||||
[feature/branch] $ git rebase --rebase-merges --strategy subtree master
|
||||
fatal: refusing to merge unrelated histories
|
||||
Could not apply 0d6a56b... Add-preexec-from-https-github-com-rcaloras-bash-preexec-0-4-1- # Add "preexec" from "https://github.com/rcaloras/bash-preexec@0.4.1"
|
||||
[feature/branch] $ git vendor add preexec https://github.com/rcaloras/bash-preexec 0.4.1
|
||||
...
|
||||
[feature/branch] $ git rebase --continue
|
||||
|
||||
If rebasing makes you a little uneasy (as it probably should). You can always test in
|
||||
another branch.
|
||||
|
||||
::
|
||||
|
||||
[feater/branch] $ git checkout -b feature/branch-test-rebase
|
||||
[feater/branch-test-rebase] $ git rebase --rebase-merges --strategy subtree master
|
||||
...
|
||||
|
||||
Afterwards you can make sure the rebase was successful by running ``git vendor list``
|
||||
to see if your library is still recognized as a vendored lib
|
||||
|
||||
::
|
||||
|
||||
[feature/branch] $ git vendor list
|
||||
preexec@0.4.1:
|
||||
name: preexec
|
||||
dir: vendor/github.com/rcaloras/bash-preexec
|
||||
repo: https://github.com/rcaloras/bash-preexec
|
||||
ref: 0.4.1
|
||||
commit: 8fe585c5cf377a3830b895fe26e694b020d8db1a
|
||||
[feature/branch] $
|
||||
|
||||
|
||||
Plugin Disable Callbacks
|
||||
------------------------
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o
|
||||
* ``battery`` - Battery information (you'll need to enable the ``battery`` plugin)
|
||||
* ``clock`` - Current time in ``HH:MM:SS`` format
|
||||
* ``cwd`` - Current working directory including full folder hierarchy (c.f. ``wd``\ )
|
||||
* ``gcloud`` - Current gcloud active account
|
||||
* ``hostname`` - Host name of machine
|
||||
* ``in_toolbox`` - Show identifier if running inside a `toolbox <https://github.com/containers/toolbox>`_
|
||||
* ``in_vim`` - Show identifier if running in ``:terminal`` from vim
|
||||
|
||||
21
hooks/dot-bash.sh
Executable file
21
hooks/dot-bash.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
exit_code=0
|
||||
for file in "$@"; do
|
||||
# Confirm file is not executable
|
||||
#
|
||||
if [[ -x "${file}" ]]; then
|
||||
echo "Bash include file \`${file}\` should not be executable"
|
||||
exit_code=1
|
||||
fi
|
||||
|
||||
# Confirm expected schellcheck header
|
||||
#
|
||||
LINE1="$(head -n 1 "${file}")"
|
||||
if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then
|
||||
echo "Bash include file \`${file}\` has bad/missing shellcheck header"
|
||||
exit_code=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $exit_code
|
||||
21
hooks/dot-sh.sh
Executable file
21
hooks/dot-sh.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
exit_code=0
|
||||
for file in "$@"; do
|
||||
# Confirm file is executable
|
||||
#
|
||||
if [[ ! -x "${file}" ]]; then
|
||||
echo "Bash file \`${file}\` is not executable"
|
||||
exit_code=1
|
||||
fi
|
||||
|
||||
# Confirm expected #! header
|
||||
#
|
||||
LINE1="$(head -n 1 "${file}")"
|
||||
if [[ "${LINE1}" != "#!/usr/bin/env bash" ]]; then
|
||||
echo "Bash file \`${file}\` has bad/missing #! header"
|
||||
exit_code=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $exit_code
|
||||
317
install.sh
317
install.sh
@@ -2,202 +2,233 @@
|
||||
# bash-it installer
|
||||
|
||||
# Show how to use this installer
|
||||
function show_usage() {
|
||||
echo -e "\n$0 : Install bash-it"
|
||||
echo -e "Usage:\n$0 [arguments] \n"
|
||||
echo "Arguments:"
|
||||
echo "--help (-h): Display this help message"
|
||||
echo "--silent (-s): Install default settings without prompting for input";
|
||||
echo "--interactive (-i): Interactively choose plugins"
|
||||
echo "--no-modify-config (-n): Do not modify existing config file"
|
||||
echo "--append-to-config (-a): Keep existing config file and append bash-it templates at the end"
|
||||
exit 0;
|
||||
function _bash-it_show_usage() {
|
||||
echo -e "\n$0 : Install bash-it"
|
||||
echo -e "Usage:\n$0 [arguments] \n"
|
||||
echo "Arguments:"
|
||||
echo "--help (-h): Display this help message"
|
||||
echo "--silent (-s): Install default settings without prompting for input"
|
||||
echo "--interactive (-i): Interactively choose plugins"
|
||||
echo "--no-modify-config (-n): Do not modify existing config file"
|
||||
echo "--append-to-config (-a): Keep existing config file and append bash-it templates at the end"
|
||||
echo "--overwrite-backup (-f): Overwrite existing backup"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# enable a thing
|
||||
function load_one() {
|
||||
file_type=$1
|
||||
file_to_enable=$2
|
||||
mkdir -p "$BASH_IT/${file_type}/enabled"
|
||||
function _bash-it_load_one() {
|
||||
file_type=$1
|
||||
file_to_enable=$2
|
||||
mkdir -p "$BASH_IT/${file_type}/enabled"
|
||||
|
||||
dest="${BASH_IT}/${file_type}/enabled/${file_to_enable}"
|
||||
if [ ! -e "${dest}" ]; then
|
||||
ln -sf "../available/${file_to_enable}" "${dest}"
|
||||
else
|
||||
echo "File ${dest} exists, skipping"
|
||||
fi
|
||||
dest="${BASH_IT}/${file_type}/enabled/${file_to_enable}"
|
||||
if [ ! -e "${dest}" ]; then
|
||||
ln -sf "../available/${file_to_enable}" "${dest}"
|
||||
else
|
||||
echo "File ${dest} exists, skipping"
|
||||
fi
|
||||
}
|
||||
|
||||
# Interactively enable several things
|
||||
function load_some() {
|
||||
file_type=$1
|
||||
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
|
||||
enable_func="_enable-$single_type"
|
||||
[ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled"
|
||||
for path in "$BASH_IT/${file_type}/available/"[^_]*
|
||||
do
|
||||
file_name=$(basename "$path")
|
||||
while true
|
||||
do
|
||||
just_the_name="${file_name%%.*}"
|
||||
read -e -n 1 -p "Would you like to enable the $just_the_name $file_type? [y/N] " RESP
|
||||
case $RESP in
|
||||
[yY])
|
||||
$enable_func $just_the_name
|
||||
break
|
||||
;;
|
||||
[nN]|"")
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[91mPlease choose y or n.\033[m"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
function _bash-it_load_some() {
|
||||
file_type=$1
|
||||
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
|
||||
enable_func="_enable-$single_type"
|
||||
[ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled"
|
||||
for path in "$BASH_IT/${file_type}/available/"[^_]*; do
|
||||
file_name=$(basename "$path")
|
||||
while true; do
|
||||
just_the_name="${file_name%%.*}"
|
||||
read -r -e -n 1 -p "Would you like to enable the $just_the_name $file_type? [y/N] " RESP
|
||||
case $RESP in
|
||||
[yY])
|
||||
$enable_func "$just_the_name"
|
||||
break
|
||||
;;
|
||||
[nN] | "")
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[91mPlease choose y or n.\033[m"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Back up existing profile
|
||||
function backup() {
|
||||
test -w "$HOME/$CONFIG_FILE" &&
|
||||
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
|
||||
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
|
||||
function _bash-it_backup() {
|
||||
test -w "$HOME/$CONFIG_FILE" \
|
||||
&& cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" \
|
||||
&& echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
|
||||
}
|
||||
|
||||
# Back up existing profile and create new one for bash-it
|
||||
function backup_new() {
|
||||
backup
|
||||
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
|
||||
echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m"
|
||||
function _bash-it_backup_new() {
|
||||
_bash-it_backup
|
||||
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
|
||||
echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m"
|
||||
}
|
||||
|
||||
# Back up existing profile and append bash-it templates at the end
|
||||
function backup_append() {
|
||||
backup
|
||||
function _bash-it_backup_append() {
|
||||
_bash-it_backup
|
||||
(sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
|
||||
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
|
||||
}
|
||||
|
||||
function _bash-it_check_for_backup() {
|
||||
if ! [[ -e "$HOME/$BACKUP_FILE" ]]; then
|
||||
return
|
||||
fi
|
||||
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
|
||||
|
||||
if ! [[ $overwrite_backup ]]; then
|
||||
while ! [[ $silent ]]; do
|
||||
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
|
||||
case $RESP in
|
||||
[yY])
|
||||
overwrite_backup=true
|
||||
break
|
||||
;;
|
||||
[nN] | "")
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[91mPlease choose y or n.\033[m"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
if ! [[ $overwrite_backup ]]; then
|
||||
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
|
||||
if [[ $silent ]]; then
|
||||
echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m"
|
||||
fi
|
||||
exit 1
|
||||
else
|
||||
echo -e "\033[0;32mOverwriting backup...\033[m"
|
||||
fi
|
||||
}
|
||||
|
||||
function _bash-it_modify_config_files() {
|
||||
_bash-it_check_for_backup
|
||||
|
||||
if ! [[ $silent ]]; then
|
||||
while ! [[ $append_to_config ]]; do
|
||||
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
|
||||
case $choice in
|
||||
[yY])
|
||||
append_to_config=true
|
||||
break
|
||||
;;
|
||||
[nN] | "")
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[91mPlease choose y or n.\033[m"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
if [[ $append_to_config ]]; then
|
||||
# backup/append
|
||||
_bash-it_backup_append
|
||||
else
|
||||
# backup/new by default
|
||||
_bash-it_backup_new
|
||||
fi
|
||||
}
|
||||
|
||||
for param in "$@"; do
|
||||
shift
|
||||
case "$param" in
|
||||
"--help") set -- "$@" "-h" ;;
|
||||
"--silent") set -- "$@" "-s" ;;
|
||||
"--interactive") set -- "$@" "-i" ;;
|
||||
"--no-modify-config") set -- "$@" "-n" ;;
|
||||
"--append-to-config") set -- "$@" "-a" ;;
|
||||
*) set -- "$@" "$param"
|
||||
esac
|
||||
shift
|
||||
case "$param" in
|
||||
"--help") set -- "$@" "-h" ;;
|
||||
"--silent") set -- "$@" "-s" ;;
|
||||
"--interactive") set -- "$@" "-i" ;;
|
||||
"--no-modify-config") set -- "$@" "-n" ;;
|
||||
"--append-to-config") set -- "$@" "-a" ;;
|
||||
"--overwrite-backup") set -- "$@" "-f" ;;
|
||||
*) set -- "$@" "$param" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
OPTIND=1
|
||||
while getopts "hsina" opt
|
||||
do
|
||||
case "$opt" in
|
||||
"h") show_usage; exit 0 ;;
|
||||
"s") silent=true ;;
|
||||
"i") interactive=true ;;
|
||||
"n") no_modify_config=true ;;
|
||||
"a") append_to_config=true ;;
|
||||
"?") show_usage >&2; exit 1 ;;
|
||||
esac
|
||||
while getopts "hsinaf" opt; do
|
||||
case "$opt" in
|
||||
"h")
|
||||
_bash-it_show_usage
|
||||
exit 0
|
||||
;;
|
||||
"s") silent=true ;;
|
||||
"i") interactive=true ;;
|
||||
"n") no_modify_config=true ;;
|
||||
"a") append_to_config=true ;;
|
||||
"f") overwrite_backup=true ;;
|
||||
"?")
|
||||
_bash-it_show_usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $(expr $OPTIND - 1)
|
||||
shift $(("$OPTIND" - 1))
|
||||
|
||||
if [[ $silent ]] && [[ $interactive ]]; then
|
||||
echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m"
|
||||
exit 1;
|
||||
echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $no_modify_config ]] && [[ $append_to_config ]]; then
|
||||
echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m"
|
||||
exit 1;
|
||||
echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASH_IT="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
CONFIG_FILE=.bash_profile
|
||||
;;
|
||||
*)
|
||||
CONFIG_FILE=.bashrc
|
||||
;;
|
||||
darwin*)
|
||||
CONFIG_FILE=.bash_profile
|
||||
;;
|
||||
*)
|
||||
CONFIG_FILE=.bashrc
|
||||
;;
|
||||
esac
|
||||
|
||||
BACKUP_FILE=$CONFIG_FILE.bak
|
||||
echo "Installing bash-it"
|
||||
if ! [[ $silent ]] && ! [[ $no_modify_config ]]; then
|
||||
if [ -e "$HOME/$BACKUP_FILE" ]; then
|
||||
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
|
||||
while ! [ $silent ]; do
|
||||
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
|
||||
case $RESP in
|
||||
[yY])
|
||||
break
|
||||
;;
|
||||
[nN]|"")
|
||||
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[91mPlease choose y or n.\033[m"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
while ! [ $append_to_config ]; do
|
||||
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
|
||||
case $choice in
|
||||
[yY])
|
||||
backup_append
|
||||
break
|
||||
;;
|
||||
[nN]|"")
|
||||
backup_new
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[91mPlease choose y or n.\033[m"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
elif [[ $append_to_config ]]; then
|
||||
# backup/append
|
||||
backup_append
|
||||
elif [[ $silent ]] && ! [[ $no_modify_config ]]; then
|
||||
# backup/new by default
|
||||
backup_new
|
||||
if ! [[ $no_modify_config ]]; then
|
||||
_bash-it_modify_config_files
|
||||
fi
|
||||
|
||||
# Disable auto-reload in case its enabled
|
||||
export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=''
|
||||
# Load dependencies for enabling components
|
||||
source "$BASH_IT/lib/composure.bash"
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
|
||||
# shellcheck source=./lib/utilities.bash
|
||||
source "$BASH_IT/lib/utilities.bash"
|
||||
cite _about _param _example _group _author _version
|
||||
# shellcheck source=./lib/helpers.bash
|
||||
source "$BASH_IT/lib/helpers.bash"
|
||||
|
||||
if [[ $interactive ]] && ! [[ $silent ]] ;
|
||||
then
|
||||
for type in "aliases" "plugins" "completion"
|
||||
do
|
||||
echo -e "\033[0;32mEnabling $type\033[0m"
|
||||
load_some $type
|
||||
done
|
||||
if [[ $interactive ]] && ! [[ $silent ]]; then
|
||||
for type in "aliases" "plugins" "completion"; do
|
||||
echo -e "\033[0;32mEnabling $type\033[0m"
|
||||
_bash-it_load_some $type
|
||||
done
|
||||
else
|
||||
echo ""
|
||||
echo -e "\033[0;32mEnabling reasonable defaults\033[0m"
|
||||
_enable-completion bash-it
|
||||
_enable-completion system
|
||||
_enable-plugin base
|
||||
_enable-plugin alias-completion
|
||||
_enable-alias general
|
||||
echo ""
|
||||
echo -e "\033[0;32mEnabling reasonable defaults\033[0m"
|
||||
_enable-completion bash-it
|
||||
_enable-completion system
|
||||
_enable-plugin base
|
||||
_enable-plugin alias-completion
|
||||
_enable-alias general
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m"
|
||||
# shellcheck disable=SC2086
|
||||
echo -e "\033[0;32mTo start using it, open a new tab or 'source "$HOME/$CONFIG_FILE"'.\033[0m"
|
||||
echo ""
|
||||
echo "To show the available aliases/completions/plugins, type one of the following:"
|
||||
|
||||
@@ -1,380 +0,0 @@
|
||||
# composure - by erichs
|
||||
# light-hearted functions for intuitive shell programming
|
||||
|
||||
# install: source this script in your ~/.profile or ~/.${SHELL}rc script
|
||||
|
||||
# latest source available at http://git.io/composure
|
||||
# known to work on bash, zsh, and ksh93
|
||||
|
||||
# 'plumbing' functions
|
||||
|
||||
composure_keywords ()
|
||||
{
|
||||
echo "about author example group param version"
|
||||
}
|
||||
|
||||
letterpress ()
|
||||
{
|
||||
typeset rightcol="$1" leftcol="${2:- }"
|
||||
|
||||
if [ -z "$rightcol" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
printf "%-20s%s\n" "$leftcol" "$rightcol"
|
||||
}
|
||||
|
||||
transcribe ()
|
||||
{
|
||||
typeset func=$1
|
||||
typeset file=$2
|
||||
typeset operation="$3"
|
||||
|
||||
if git --version >/dev/null 2>&1; then
|
||||
if [ -d ~/.composure ]; then
|
||||
(
|
||||
cd ~/.composure
|
||||
if git rev-parse 2>/dev/null; then
|
||||
if [ ! -f $file ]; then
|
||||
printf "%s\n" "Oops! Couldn't find $file to version it for you..."
|
||||
return
|
||||
fi
|
||||
cp $file ~/.composure/$func.inc
|
||||
git add --all .
|
||||
git commit -m "$operation $func"
|
||||
fi
|
||||
)
|
||||
else
|
||||
if [ "$USE_COMPOSURE_REPO" = "0" ]; then
|
||||
return # if you say so...
|
||||
fi
|
||||
printf "%s\n" "I see you don't have a ~/.composure repo..."
|
||||
typeset input
|
||||
typeset valid=0
|
||||
while [ $valid != 1 ]; do
|
||||
printf "\n%s" 'would you like to create one? y/n: '
|
||||
read input
|
||||
case $input in
|
||||
y|yes|Y|Yes|YES)
|
||||
(
|
||||
echo 'creating git repository for your functions...'
|
||||
mkdir ~/.composure
|
||||
cd ~/.composure
|
||||
git init
|
||||
echo "composure stores your function definitions here" > README.txt
|
||||
git add README.txt
|
||||
git commit -m 'initial commit'
|
||||
)
|
||||
# if at first you don't succeed...
|
||||
transcribe "$func" "$file" "$operation"
|
||||
valid=1
|
||||
;;
|
||||
n|no|N|No|NO)
|
||||
printf "%s\n" "ok. add 'export USE_COMPOSURE_REPO=0' to your startup script to disable this message."
|
||||
valid=1
|
||||
;;
|
||||
*)
|
||||
printf "%s\n" "sorry, didn't get that..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
typeset_functions ()
|
||||
{
|
||||
# unfortunately, there does not seem to be a easy, portable way to list just the
|
||||
# names of the defined shell functions...
|
||||
|
||||
# first, determine our shell:
|
||||
typeset shell
|
||||
if [ -n "$SHELL" ]; then
|
||||
shell=$(basename $SHELL) # we assume this is set correctly!
|
||||
else
|
||||
# we'll have to try harder
|
||||
# here's a hack I modified from a StackOverflow post:
|
||||
# we loop over the ps listing for the current process ($$), and print the last column (CMD)
|
||||
# stripping any leading hyphens bash sometimes throws in there
|
||||
typeset x ans
|
||||
typeset this=$(for x in $(ps -p $$); do ans=$x; done; printf "%s\n" $ans | sed 's/^-*//')
|
||||
typeset shell=$(basename $this) # e.g. /bin/bash => bash
|
||||
fi
|
||||
case "$shell" in
|
||||
bash)
|
||||
typeset -F | awk '{print $3}'
|
||||
;;
|
||||
*)
|
||||
# trim everything following '()' in ksh
|
||||
typeset +f | sed 's/().*$//'
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
# bootstrap metadata keywords for porcelain functions
|
||||
for f in $(composure_keywords)
|
||||
do
|
||||
eval "$f() { :; }"
|
||||
done
|
||||
unset f
|
||||
|
||||
|
||||
# 'porcelain' functions
|
||||
|
||||
cite ()
|
||||
{
|
||||
about creates one or more meta keywords for use in your functions
|
||||
param one or more keywords
|
||||
example '$ cite url username'
|
||||
example '$ url http://somewhere.com'
|
||||
example '$ username alice'
|
||||
group composure
|
||||
|
||||
# this is the storage half of the 'metadata' system:
|
||||
# we create dynamic metadata keywords with function wrappers around
|
||||
# the NOP command, ':'
|
||||
|
||||
# anything following a keyword will get parsed as a positional
|
||||
# parameter, but stay resident in the ENV. As opposed to shell
|
||||
# comments, '#', which do not get parsed and are not available
|
||||
# at runtime.
|
||||
|
||||
# a BIG caveat--your metadata must be roughly parsable: do not use
|
||||
# contractions, and consider single or double quoting if it contains
|
||||
# non-alphanumeric characters
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
printf '%s\n' 'missing parameter(s)'
|
||||
reference cite
|
||||
return
|
||||
fi
|
||||
|
||||
typeset keyword
|
||||
for keyword in $*; do
|
||||
eval "$keyword() { :; }"
|
||||
done
|
||||
}
|
||||
|
||||
draft ()
|
||||
{
|
||||
about wraps command from history into a new function, default is last command
|
||||
param 1: name to give function
|
||||
param 2: optional history line number
|
||||
example '$ ls'
|
||||
example '$ draft list'
|
||||
example '$ draft newfunc 1120 # wraps command at history line 1120 in newfunc()'
|
||||
group composure
|
||||
|
||||
typeset func=$1
|
||||
typeset num=$2
|
||||
typeset cmd
|
||||
|
||||
if [ -z "$func" ]; then
|
||||
printf '%s\n' 'missing parameter(s)'
|
||||
reference draft
|
||||
return
|
||||
fi
|
||||
|
||||
# aliases bind tighter than function names, disallow them
|
||||
if [ -n "$(LANG=C type -t $func 2>/dev/null | grep 'alias')" ]; then
|
||||
printf '%s\n' "sorry, $(type -a $func). please choose another name."
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -z "$num" ]; then
|
||||
# parse last command from fc output
|
||||
# some versions of 'fix command, fc' need corrective lenses...
|
||||
typeset myopic=$(fc -ln -1 | grep draft)
|
||||
typeset lines=1
|
||||
if [ -n "$myopic" ]; then
|
||||
lines=2
|
||||
fi
|
||||
cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//')
|
||||
else
|
||||
# parse command from history line number
|
||||
cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//')
|
||||
fi
|
||||
eval "$func() { $cmd; }"
|
||||
typeset file=$(mktemp -t draft.XXXX)
|
||||
typeset -f $func > $file
|
||||
transcribe $func $file draft
|
||||
rm $file 2>/dev/null
|
||||
}
|
||||
|
||||
glossary ()
|
||||
{
|
||||
about displays help summary for all functions, or summary for a group of functions
|
||||
param 1: optional, group name
|
||||
example '$ glossary'
|
||||
example '$ glossary misc'
|
||||
group composure
|
||||
|
||||
typeset targetgroup=${1:-}
|
||||
|
||||
for func in $(typeset_functions); do
|
||||
if [ -n "$targetgroup" ]; then
|
||||
typeset group="$(typeset -f $func | metafor group)"
|
||||
if [ "$group" != "$targetgroup" ]; then
|
||||
continue # skip non-matching groups, if specified
|
||||
fi
|
||||
fi
|
||||
typeset about="$(typeset -f $func | metafor about)"
|
||||
letterpress "$about" $func
|
||||
done
|
||||
}
|
||||
|
||||
metafor ()
|
||||
{
|
||||
about prints function metadata associated with keyword
|
||||
param 1: meta keyword
|
||||
example '$ typeset -f glossary | metafor example'
|
||||
group composure
|
||||
|
||||
typeset keyword=$1
|
||||
|
||||
if [ -z "$keyword" ]; then
|
||||
printf '%s\n' 'missing parameter(s)'
|
||||
reference metafor
|
||||
return
|
||||
fi
|
||||
|
||||
# this sed-fu is the retrieval half of the 'metadata' system:
|
||||
# 'grep' for the metadata keyword, and then parse/filter the matching line
|
||||
|
||||
# grep keyword # strip trailing '|"|; # ignore thru keyword and leading '|"
|
||||
sed -n "/$keyword / s/['\";]*$//;s/^[ ]*$keyword ['\"]*\([^([].*\)*$/\1/p"
|
||||
}
|
||||
|
||||
reference ()
|
||||
{
|
||||
about displays apidoc help for a specific function
|
||||
param 1: function name
|
||||
example '$ reference revise'
|
||||
group composure
|
||||
|
||||
typeset func=$1
|
||||
if [ -z "$func" ]; then
|
||||
printf '%s\n' 'missing parameter(s)'
|
||||
reference reference
|
||||
return
|
||||
fi
|
||||
|
||||
typeset line
|
||||
|
||||
typeset about="$(typeset -f $func | metafor about)"
|
||||
letterpress "$about" $func
|
||||
|
||||
typeset author="$(typeset -f $func | metafor author)"
|
||||
if [ -n "$author" ]; then
|
||||
letterpress "$author" 'author:'
|
||||
fi
|
||||
|
||||
typeset version="$(typeset -f $func | metafor version)"
|
||||
if [ -n "$version" ]; then
|
||||
letterpress "$version" 'version:'
|
||||
fi
|
||||
|
||||
if [ -n "$(typeset -f $func | metafor param)" ]; then
|
||||
printf "parameters:\n"
|
||||
typeset -f $func | metafor param | while read line
|
||||
do
|
||||
letterpress "$line"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "$(typeset -f $func | metafor example)" ]; then
|
||||
printf "examples:\n"
|
||||
typeset -f $func | metafor example | while read line
|
||||
do
|
||||
letterpress "$line"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
revise ()
|
||||
{
|
||||
about loads function into editor for revision
|
||||
param 1: name of function
|
||||
example '$ revise myfunction'
|
||||
group composure
|
||||
|
||||
typeset func=$1
|
||||
typeset temp=$(mktemp -t revise.XXXX)
|
||||
|
||||
if [ -z "$func" ]; then
|
||||
printf '%s\n' 'missing parameter(s)'
|
||||
reference revise
|
||||
return
|
||||
fi
|
||||
|
||||
# populate tempfile...
|
||||
if [ -f ~/.composure/$func.inc ]; then
|
||||
# ...with contents of latest git revision...
|
||||
cat ~/.composure/$func.inc >> $temp
|
||||
else
|
||||
# ...or from ENV if not previously versioned
|
||||
typeset -f $func >> $temp
|
||||
fi
|
||||
|
||||
if [ -z "$EDITOR" ]
|
||||
then
|
||||
typeset EDITOR=vi
|
||||
fi
|
||||
|
||||
$EDITOR $temp
|
||||
. $temp # source edited file
|
||||
|
||||
transcribe $func $temp revise
|
||||
rm $temp
|
||||
}
|
||||
|
||||
write ()
|
||||
{
|
||||
about writes one or more composed function definitions to stdout
|
||||
param one or more function names
|
||||
example '$ write finddown foo'
|
||||
example '$ write finddown'
|
||||
group composure
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
printf '%s\n' 'missing parameter(s)'
|
||||
reference write
|
||||
return
|
||||
fi
|
||||
|
||||
# bootstrap metadata
|
||||
cat <<END
|
||||
for f in $(composure_keywords)
|
||||
do
|
||||
eval "\$f() { :; }"
|
||||
done
|
||||
unset f
|
||||
END
|
||||
|
||||
# include cite() to enable custom keywords
|
||||
typeset -f cite $*
|
||||
}
|
||||
|
||||
: <<EOF
|
||||
License: The MIT License
|
||||
|
||||
Copyright © 2012 Erich Smith
|
||||
|
||||
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.
|
||||
EOF
|
||||
@@ -37,6 +37,17 @@ function _binary_exists ()
|
||||
type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ;
|
||||
}
|
||||
|
||||
function _completion_exists ()
|
||||
{
|
||||
_about 'checks for existence of a completion'
|
||||
_param '1: command to check'
|
||||
_param '2: (optional) log message to include when completion is found'
|
||||
_example '$ _completion_exists gh && echo exists'
|
||||
_group 'lib'
|
||||
local msg="${2:-Completion for '$1' already exists!}"
|
||||
complete -p "$1" &> /dev/null && _log_warning "$msg" ;
|
||||
}
|
||||
|
||||
function _make_reload_alias() {
|
||||
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
|
||||
}
|
||||
@@ -731,14 +742,14 @@ _help-plugins()
|
||||
printf '%s' 'please wait, building help...'
|
||||
typeset grouplist=$(mktemp -t grouplist.XXXXXX)
|
||||
typeset func
|
||||
for func in $(typeset_functions)
|
||||
for func in $(_typeset_functions)
|
||||
do
|
||||
typeset group="$(typeset -f $func | metafor group)"
|
||||
if [ -z "$group" ]; then
|
||||
group='misc'
|
||||
fi
|
||||
typeset about="$(typeset -f $func | metafor about)"
|
||||
letterpress "$about" $func >> $grouplist.$group
|
||||
_letterpress "$about" $func >> $grouplist.$group
|
||||
echo $grouplist.$group >> $grouplist
|
||||
done
|
||||
# clear progress message
|
||||
@@ -777,7 +788,7 @@ all_groups ()
|
||||
|
||||
typeset func
|
||||
typeset file=$(mktemp -t composure.XXXX)
|
||||
for func in $(typeset_functions)
|
||||
for func in $(_typeset_functions)
|
||||
do
|
||||
typeset -f $func | metafor group >> $file
|
||||
done
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Bash History Handling
|
||||
|
||||
shopt -s histappend # append to bash_history if Terminal.app quits
|
||||
export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups} # erase duplicates; alternative option: export HISTCONTROL=ignoredups
|
||||
export HISTSIZE=${HISTSIZE:-5000} # resize history size
|
||||
export AUTOFEATURE=${AUTOFEATURE:-true autotest} # Cucumber / Autotest integration
|
||||
|
||||
function rh {
|
||||
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
|
||||
}
|
||||
199
lib/preexec.bash
199
lib/preexec.bash
@@ -1,199 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# http://www.twistedmatrix.com/users/glyph/preexec.bash.txt
|
||||
# preexec.bash -- Bash support for ZSH-like 'preexec' and 'precmd' functions.
|
||||
|
||||
# The 'preexec' function is executed before each interactive command is
|
||||
# executed, with the interactive command as its argument. The 'precmd'
|
||||
# function is executed before each prompt is displayed.
|
||||
|
||||
# To use, in order:
|
||||
|
||||
# 1. source this file
|
||||
# 2. define 'preexec' and/or 'precmd' functions (AFTER sourcing this file),
|
||||
# 3. as near as possible to the end of your shell setup, run 'preexec_install'
|
||||
# to kick everything off.
|
||||
|
||||
# Note: this module requires 2 bash features which you must not otherwise be
|
||||
# using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. preexec_install
|
||||
# will override these and if you override one or the other this _will_ break.
|
||||
|
||||
# This is known to support bash3, as well as *mostly* support bash2.05b. It
|
||||
# has been tested with the default shells on MacOS X 10.4 "Tiger", Ubuntu 5.10
|
||||
# "Breezy Badger", Ubuntu 6.06 "Dapper Drake", and Ubuntu 6.10 "Edgy Eft".
|
||||
|
||||
|
||||
# Copy screen-run variables from the remote host, if they're available.
|
||||
|
||||
if [[ "$SCREEN_RUN_HOST" == "" ]]
|
||||
then
|
||||
SCREEN_RUN_HOST="$LC_SCREEN_RUN_HOST"
|
||||
SCREEN_RUN_USER="$LC_SCREEN_RUN_USER"
|
||||
fi
|
||||
|
||||
# This variable describes whether we are currently in "interactive mode";
|
||||
# i.e. whether this shell has just executed a prompt and is waiting for user
|
||||
# input. It documents whether the current command invoked by the trace hook is
|
||||
# run interactively by the user; it's set immediately after the prompt hook,
|
||||
# and unset as soon as the trace hook is run.
|
||||
preexec_interactive_mode=""
|
||||
|
||||
# Default do-nothing implementation of preexec.
|
||||
function preexec () {
|
||||
true
|
||||
}
|
||||
|
||||
# Default do-nothing implementation of precmd.
|
||||
function precmd () {
|
||||
true
|
||||
}
|
||||
|
||||
# This function is installed as the PROMPT_COMMAND; it is invoked before each
|
||||
# interactive prompt display. It sets a variable to indicate that the prompt
|
||||
# was just displayed, to allow the DEBUG trap, below, to know that the next
|
||||
# command is likely interactive.
|
||||
function preexec_invoke_cmd () {
|
||||
precmd
|
||||
preexec_interactive_mode="yes"
|
||||
}
|
||||
|
||||
# This function is installed as the DEBUG trap. It is invoked before each
|
||||
# interactive prompt display. Its purpose is to inspect the current
|
||||
# environment to attempt to detect if the current command is being invoked
|
||||
# interactively, and invoke 'preexec' if so.
|
||||
function preexec_invoke_exec () {
|
||||
if [[ -n "$COMP_LINE" ]]
|
||||
then
|
||||
# We're in the middle of a completer. This obviously can't be
|
||||
# an interactively issued command.
|
||||
return
|
||||
fi
|
||||
if [[ -z "$preexec_interactive_mode" ]]
|
||||
then
|
||||
# We're doing something related to displaying the prompt. Let the
|
||||
# prompt set the title instead of me.
|
||||
return
|
||||
else
|
||||
# If we're in a subshell, then the prompt won't be re-displayed to put
|
||||
# us back into interactive mode, so let's not set the variable back.
|
||||
# In other words, if you have a subshell like
|
||||
# (sleep 1; sleep 2)
|
||||
# You want to see the 'sleep 2' as a set_command_title as well.
|
||||
if [[ 0 -eq "$BASH_SUBSHELL" ]]
|
||||
then
|
||||
preexec_interactive_mode=""
|
||||
fi
|
||||
fi
|
||||
if [[ "preexec_invoke_cmd" == "$BASH_COMMAND" ]]
|
||||
then
|
||||
# Sadly, there's no cleaner way to detect two prompts being displayed
|
||||
# one after another. This makes it important that PROMPT_COMMAND
|
||||
# remain set _exactly_ as below in preexec_install. Let's switch back
|
||||
# out of interactive mode and not trace any of the commands run in
|
||||
# precmd.
|
||||
|
||||
# Given their buggy interaction between BASH_COMMAND and debug traps,
|
||||
# versions of bash prior to 3.1 can't detect this at all.
|
||||
preexec_interactive_mode=""
|
||||
return
|
||||
fi
|
||||
|
||||
# In more recent versions of bash, this could be set via the "BASH_COMMAND"
|
||||
# variable, but using history here is better in some ways: for example, "ps
|
||||
# auxf | less" will show up with both sides of the pipe if we use history,
|
||||
# but only as "ps auxf" if not.
|
||||
local this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`;
|
||||
|
||||
# If none of the previous checks have earlied out of this function, then
|
||||
# the command is in fact interactive and we should invoke the user's
|
||||
# preexec hook with the running command as an argument.
|
||||
preexec "$this_command"
|
||||
}
|
||||
|
||||
# Execute this to set up preexec and precmd execution.
|
||||
function preexec_install () {
|
||||
|
||||
# *BOTH* of these options need to be set for the DEBUG trap to be invoked
|
||||
# in ( ) subshells. This smells like a bug in bash to me. The null stderr
|
||||
# redirections are to quiet errors on bash2.05 (i.e. OSX's default shell)
|
||||
# where the options can't be set, and it's impossible to inherit the trap
|
||||
# into subshells.
|
||||
|
||||
set -o functrace > /dev/null 2>&1
|
||||
shopt -s extdebug > /dev/null 2>&1
|
||||
|
||||
# Finally, install the actual traps.
|
||||
if [[ ! -z "${PROMPT_COMMAND// }" ]]; then
|
||||
PROMPT_COMMAND="${PROMPT_COMMAND}"$'\n'"preexec_invoke_cmd"
|
||||
else
|
||||
PROMPT_COMMAND="preexec_invoke_cmd"
|
||||
fi
|
||||
trap 'preexec_invoke_exec' DEBUG
|
||||
}
|
||||
|
||||
# Since this is the reason that 99% of everybody is going to bother with a
|
||||
# pre-exec hook anyway, we'll include it in this module.
|
||||
|
||||
# Change the title of the xterm.
|
||||
function preexec_xterm_title () {
|
||||
local title="$1"
|
||||
echo -ne "\033]0;$title\007" > /dev/stderr
|
||||
}
|
||||
|
||||
function preexec_screen_title () {
|
||||
local title="$1"
|
||||
echo -ne "\033k$1\033\\" > /dev/stderr
|
||||
}
|
||||
|
||||
# Abbreviate the "user@host" string as much as possible to preserve space in
|
||||
# screen titles. Elide the host if the host is the same, elide the user if the
|
||||
# user is the same.
|
||||
function preexec_screen_user_at_host () {
|
||||
local RESULT=""
|
||||
if [[ "$SCREEN_RUN_HOST" == "$SCREEN_HOST" ]]
|
||||
then
|
||||
return
|
||||
else
|
||||
if [[ "$SCREEN_RUN_USER" == "$USER" ]]
|
||||
then
|
||||
echo -n "@${SCREEN_HOST}"
|
||||
else
|
||||
echo -n "${USER}@${SCREEN_HOST}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function preexec_xterm_title_install () {
|
||||
# These functions are defined here because they only make sense with the
|
||||
# preexec_install below.
|
||||
function precmd () {
|
||||
preexec_xterm_title "${TERM} - ${USER}@${SCREEN_HOST} `dirs -0` $PROMPTCHAR"
|
||||
if [[ "${TERM}" == screen ]]
|
||||
then
|
||||
preexec_screen_title "`preexec_screen_user_at_host`${PROMPTCHAR}"
|
||||
fi
|
||||
}
|
||||
|
||||
function preexec () {
|
||||
preexec_xterm_title "${TERM} - $1 {`dirs -0`} (${USER}@${SCREEN_HOST})"
|
||||
if [[ "${TERM}" == screen ]]
|
||||
then
|
||||
local cutit="$1"
|
||||
local cmdtitle=`echo "$cutit" | cut -d " " -f 1`
|
||||
if [[ "$cmdtitle" == "exec" ]]
|
||||
then
|
||||
local cmdtitle=`echo "$cutit" | cut -d " " -f 2`
|
||||
fi
|
||||
if [[ "$cmdtitle" == "screen" ]]
|
||||
then
|
||||
# Since stacked screens are quite common, it would be nice to
|
||||
# just display them as '$$'.
|
||||
local cmdtitle="${PROMPTCHAR}"
|
||||
else
|
||||
local cmdtitle=":$cmdtitle"
|
||||
fi
|
||||
preexec_screen_title "`preexec_screen_user_at_host`${PROMPTCHAR}$cmdtitle"
|
||||
fi
|
||||
}
|
||||
|
||||
preexec_install
|
||||
}
|
||||
16
plugins/available/basher.plugin.bash
Normal file
16
plugins/available/basher.plugin.bash
Normal file
@@ -0,0 +1,16 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'initializes basher, the shell package manager'
|
||||
|
||||
# https://github.com/basherpm/basher
|
||||
|
||||
if ! _command_exists basher; then
|
||||
if [[ -x "$HOME/.basher/bin/basher" ]]; then
|
||||
pathmunge "$HOME/.basher/bin"
|
||||
else
|
||||
_log_warning 'basher not found'
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
eval "$(basher init - bash)"
|
||||
16
plugins/available/cmd-returned-notify.plugin.bash
Normal file
16
plugins/available/cmd-returned-notify.plugin.bash
Normal file
@@ -0,0 +1,16 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
|
||||
|
||||
precmd_return_notification() {
|
||||
export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)}))
|
||||
[[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a"
|
||||
export LAST_COMMAND_TIME=
|
||||
}
|
||||
|
||||
preexec_return_notification() {
|
||||
[ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s)
|
||||
}
|
||||
|
||||
precmd_functions+=(precmd_return_notification)
|
||||
preexec_functions+=(preexec_return_notification)
|
||||
@@ -1,13 +1,5 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Helpers to get Docker setup correctly for docker-machine'
|
||||
|
||||
[ -z ${BASH_IT_DOCKER_MACHINE+x} ] && BASH_IT_DOCKER_MACHINE='dev'
|
||||
|
||||
# Note, this might need to be different if you use a machine other than 'dev'
|
||||
if [[ `uname -s` == "Darwin" ]]; then
|
||||
# check if dev machine is running
|
||||
docker-machine ls | grep --quiet "$BASH_IT_DOCKER_MACHINE.*Running"
|
||||
if [[ "$?" = "0" ]]; then
|
||||
eval "$(docker-machine env $BASH_IT_DOCKER_MACHINE)"
|
||||
fi
|
||||
fi
|
||||
_log_warning '"docker-machine" is now deprecated, and as such the plugin for it is also deprecated.
|
||||
Please disable this plugin.'
|
||||
|
||||
@@ -1,275 +1,317 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'git helper functions'
|
||||
|
||||
function git_remote {
|
||||
about 'adds remote $GIT_HOSTING:$1 to current repo'
|
||||
group 'git'
|
||||
about "adds remote $GIT_HOSTING:$1 to current repo"
|
||||
group "git"
|
||||
|
||||
echo "Running: git remote add origin ${GIT_HOSTING}:$1.git"
|
||||
git remote add origin $GIT_HOSTING:$1.git
|
||||
echo "Running: git remote add origin ${GIT_HOSTING}:$1.git"
|
||||
git remote add origin "$GIT_HOSTING:$1".git
|
||||
}
|
||||
|
||||
function git_first_push {
|
||||
about 'push into origin refs/heads/master'
|
||||
group 'git'
|
||||
about 'push into origin refs/heads/master'
|
||||
group 'git'
|
||||
|
||||
echo "Running: git push origin master:refs/heads/master"
|
||||
git push origin master:refs/heads/master
|
||||
echo "Running: git push origin master:refs/heads/master"
|
||||
git push origin master:refs/heads/master
|
||||
}
|
||||
|
||||
function git_pub() {
|
||||
about 'publishes current branch to remote origin'
|
||||
group 'git'
|
||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
about 'publishes current branch to remote origin'
|
||||
group 'git'
|
||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
echo "Publishing ${BRANCH} to remote origin"
|
||||
git push -u origin $BRANCH
|
||||
echo "Publishing ${BRANCH} to remote origin"
|
||||
git push -u origin "$BRANCH"
|
||||
}
|
||||
|
||||
function git_revert() {
|
||||
about 'applies changes to HEAD that revert all changes after this commit'
|
||||
group 'git'
|
||||
about 'applies changes to HEAD that revert all changes after this commit'
|
||||
group 'git'
|
||||
|
||||
git reset $1
|
||||
git reset --soft HEAD@{1}
|
||||
git commit -m "Revert to ${1}"
|
||||
git reset --hard
|
||||
git reset "$1"
|
||||
git reset --soft "HEAD@{1}"
|
||||
git commit -m "Revert to ${1}"
|
||||
git reset --hard
|
||||
}
|
||||
|
||||
function git_rollback() {
|
||||
about 'resets the current HEAD to this commit'
|
||||
group 'git'
|
||||
about 'resets the current HEAD to this commit'
|
||||
group 'git'
|
||||
|
||||
function is_clean() {
|
||||
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
|
||||
echo "Your branch is dirty, please commit your changes"
|
||||
kill -INT $$
|
||||
fi
|
||||
}
|
||||
function is_clean() {
|
||||
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
|
||||
echo "Your branch is dirty, please commit your changes"
|
||||
kill -INT $$
|
||||
fi
|
||||
}
|
||||
|
||||
function commit_exists() {
|
||||
git rev-list --quiet $1
|
||||
status=$?
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Commit ${1} does not exist"
|
||||
kill -INT $$
|
||||
fi
|
||||
}
|
||||
function commit_exists() {
|
||||
git rev-list --quiet "$1"
|
||||
status=$?
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Commit ${1} does not exist"
|
||||
kill -INT $$
|
||||
fi
|
||||
}
|
||||
|
||||
function keep_changes() {
|
||||
while true
|
||||
do
|
||||
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
|
||||
case $RESP
|
||||
in
|
||||
[yY])
|
||||
echo "Rolling back to commit ${1} with unstaged changes"
|
||||
git reset $1
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
echo "Rolling back to commit ${1} with a clean working tree"
|
||||
git reset --hard $1
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
esac
|
||||
done
|
||||
}
|
||||
function keep_changes() {
|
||||
while true; do
|
||||
# shellcheck disable=SC2162
|
||||
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
|
||||
case $RESP in
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
is_clean
|
||||
commit_exists $1
|
||||
[yY])
|
||||
echo "Rolling back to commit ${1} with unstaged changes"
|
||||
git reset "$1"
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
echo "Rolling back to commit ${1} with a clean working tree"
|
||||
git reset --hard "$1"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
while true
|
||||
do
|
||||
read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP
|
||||
case $RESP
|
||||
in
|
||||
[yY])
|
||||
keep_changes $1
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
esac
|
||||
done
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
is_clean
|
||||
commit_exists "$1"
|
||||
|
||||
while true; do
|
||||
# shellcheck disable=SC2162
|
||||
read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP
|
||||
case $RESP in
|
||||
|
||||
[yY])
|
||||
keep_changes "$1"
|
||||
break
|
||||
;;
|
||||
[nN])
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter Y or N"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
}
|
||||
|
||||
function git_remove_missing_files() {
|
||||
about "git rm's missing files"
|
||||
group 'git'
|
||||
about "git rm's missing files"
|
||||
group 'git'
|
||||
|
||||
git ls-files -d -z | xargs -0 git update-index --remove
|
||||
git ls-files -d -z | xargs -0 git update-index --remove
|
||||
}
|
||||
|
||||
# Adds files to git's exclude file (same as .gitignore)
|
||||
function local-ignore() {
|
||||
about 'adds file or path to git exclude file'
|
||||
param '1: file or path fragment to ignore'
|
||||
group 'git'
|
||||
echo "$1" >> .git/info/exclude
|
||||
about 'adds file or path to git exclude file'
|
||||
param '1: file or path fragment to ignore'
|
||||
group 'git'
|
||||
echo "$1" >> .git/info/exclude
|
||||
}
|
||||
|
||||
# get a quick overview for your git repo
|
||||
function git_info() {
|
||||
about 'overview for your git repo'
|
||||
group 'git'
|
||||
about 'overview for your git repo'
|
||||
group 'git'
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
# print informations
|
||||
echo "git repo overview"
|
||||
echo "-----------------"
|
||||
echo
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
# print informations
|
||||
echo "git repo overview"
|
||||
echo "-----------------"
|
||||
echo
|
||||
|
||||
# print all remotes and thier details
|
||||
for remote in $(git remote show); do
|
||||
echo $remote:
|
||||
git remote show $remote
|
||||
echo
|
||||
done
|
||||
# print all remotes and thier details
|
||||
for remote in $(git remote show); do
|
||||
echo "$remote":
|
||||
git remote show "$remote"
|
||||
echo
|
||||
done
|
||||
|
||||
# print status of working repo
|
||||
echo "status:"
|
||||
if [ -n "$(git status -s 2> /dev/null)" ]; then
|
||||
git status -s
|
||||
else
|
||||
echo "working directory is clean"
|
||||
fi
|
||||
# print status of working repo
|
||||
echo "status:"
|
||||
if [ -n "$(git status -s 2> /dev/null)" ]; then
|
||||
git status -s
|
||||
else
|
||||
echo "working directory is clean"
|
||||
fi
|
||||
|
||||
# print at least 5 last log entries
|
||||
echo
|
||||
echo "log:"
|
||||
git log -5 --oneline
|
||||
echo
|
||||
# print at least 5 last log entries
|
||||
echo
|
||||
echo "log:"
|
||||
git log -5 --oneline
|
||||
echo
|
||||
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function git_stats {
|
||||
about 'display stats per author'
|
||||
group 'git'
|
||||
about 'display stats per author'
|
||||
group 'git'
|
||||
|
||||
# awesome work from https://github.com/esc/git-stats
|
||||
# including some modifications
|
||||
# awesome work from https://github.com/esc/git-stats
|
||||
# including some modifications
|
||||
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
echo "Number of commits per author:"
|
||||
git --no-pager shortlog -sn --all
|
||||
AUTHORS=$( git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
|
||||
LOGOPTS=""
|
||||
if [ "$1" == '-w' ]; then
|
||||
LOGOPTS="$LOGOPTS -w"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-M' ]; then
|
||||
LOGOPTS="$LOGOPTS -M"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-C' ]; then
|
||||
LOGOPTS="$LOGOPTS -C --find-copies-harder"
|
||||
shift
|
||||
fi
|
||||
for a in $AUTHORS
|
||||
do
|
||||
echo '-------------------'
|
||||
echo "Statistics for: $a"
|
||||
echo -n "Number of files changed: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f3 | sort -iu | wc -l
|
||||
echo -n "Number of lines added: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f1 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of lines deleted: "
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f2 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of merges: "
|
||||
git log $LOGOPTS --all --merges --author=$a | grep -c '^commit'
|
||||
done
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
|
||||
echo "Number of commits per author:"
|
||||
git --no-pager shortlog -sn --all
|
||||
AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
|
||||
LOGOPTS=""
|
||||
if [ "$1" == '-w' ]; then
|
||||
LOGOPTS="$LOGOPTS -w"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-M' ]; then
|
||||
LOGOPTS="$LOGOPTS -M"
|
||||
shift
|
||||
fi
|
||||
if [ "$1" == '-C' ]; then
|
||||
LOGOPTS="$LOGOPTS -C --find-copies-harder"
|
||||
shift
|
||||
fi
|
||||
for a in $AUTHORS; do
|
||||
echo '-------------------'
|
||||
echo "Statistics for: $a"
|
||||
echo -n "Number of files changed: "
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f3 | sort -iu | wc -l
|
||||
echo -n "Number of lines added: "
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f1 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of lines deleted: "
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f2 | awk '{s+=$1} END {print s}'
|
||||
echo -n "Number of merges: "
|
||||
# shellcheck disable=SC2086
|
||||
git log $LOGOPTS --all --merges --author="$a" | grep -c '^commit'
|
||||
done
|
||||
else
|
||||
echo "you're currently not in a git repository"
|
||||
fi
|
||||
}
|
||||
|
||||
function gittowork() {
|
||||
about 'Places the latest .gitignore file for a given project type in the current directory, or concatenates onto an existing .gitignore'
|
||||
group 'git'
|
||||
param '1: the language/type of the project, used for determining the contents of the .gitignore file'
|
||||
example '$ gittowork java'
|
||||
about 'Places the latest .gitignore file for a given project type in the current directory, or concatenates onto an existing .gitignore'
|
||||
group 'git'
|
||||
param '1: the language/type of the project, used for determining the contents of the .gitignore file'
|
||||
example '$ gittowork java'
|
||||
|
||||
result=$(curl -L "https://www.gitignore.io/api/$1" 2>/dev/null)
|
||||
result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null)
|
||||
|
||||
if [[ $result =~ ERROR ]]; then
|
||||
echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'"
|
||||
elif [[ $1 = list ]]; then
|
||||
echo "$result"
|
||||
else
|
||||
if [[ -f .gitignore ]]; then
|
||||
result=`echo "$result" | grep -v "# Created by http://www.gitignore.io"`
|
||||
echo ".gitignore already exists, appending..."
|
||||
echo "$result" >> .gitignore
|
||||
else
|
||||
echo "$result" > .gitignore
|
||||
fi
|
||||
fi
|
||||
if [[ $result =~ ERROR ]]; then
|
||||
echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'"
|
||||
elif [[ $1 = list ]]; then
|
||||
echo "$result"
|
||||
else
|
||||
if [[ -f .gitignore ]]; then
|
||||
result=$(echo "$result" | grep -v "# Created by http://www.gitignore.io")
|
||||
echo ".gitignore already exists, appending..."
|
||||
echo "$result" >> .gitignore
|
||||
else
|
||||
echo "$result" > .gitignore
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function gitignore-reload() {
|
||||
about 'Empties the git cache, and readds all files not blacklisted by .gitignore'
|
||||
group 'git'
|
||||
example '$ gitignore-reload'
|
||||
about 'Empties the git cache, and readds all files not blacklisted by .gitignore'
|
||||
group 'git'
|
||||
example '$ gitignore-reload'
|
||||
|
||||
# The .gitignore file should not be reloaded if there are uncommited changes.
|
||||
# Firstly, require a clean work tree. The function require_clean_work_tree()
|
||||
# was stolen with love from https://www.spinics.net/lists/git/msg142043.html
|
||||
# The .gitignore file should not be reloaded if there are uncommited changes.
|
||||
# Firstly, require a clean work tree. The function require_clean_work_tree()
|
||||
# was stolen with love from https://www.spinics.net/lists/git/msg142043.html
|
||||
|
||||
# Begin require_clean_work_tree()
|
||||
# Begin require_clean_work_tree()
|
||||
|
||||
# Update the index
|
||||
git update-index -q --ignore-submodules --refresh
|
||||
err=0
|
||||
# Update the index
|
||||
git update-index -q --ignore-submodules --refresh
|
||||
err=0
|
||||
|
||||
# Disallow unstaged changes in the working tree
|
||||
if ! git diff-files --quiet --ignore-submodules --
|
||||
then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains unstaged changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
# Disallow unstaged changes in the working tree
|
||||
if ! git diff-files --quiet --ignore-submodules --; then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains unstaged changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
|
||||
# Disallow uncommited changes in the index
|
||||
if ! git diff-index --cached --quiet HEAD --ignore-submodules
|
||||
then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains uncommited changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
# Disallow uncommited changes in the index
|
||||
if ! git diff-index --cached --quiet HEAD --ignore-submodules; then
|
||||
echo >&2 "ERROR: Cannot reload .gitignore: Your index contains uncommited changes."
|
||||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
|
||||
err=1
|
||||
fi
|
||||
|
||||
# Prompt user to commit or stash changes and exit
|
||||
if [ $err = 1 ]
|
||||
then
|
||||
echo >&2 "Please commit or stash them."
|
||||
fi
|
||||
# Prompt user to commit or stash changes and exit
|
||||
if [ $err = 1 ]; then
|
||||
echo >&2 "Please commit or stash them."
|
||||
fi
|
||||
|
||||
# End require_clean_work_tree()
|
||||
# End require_clean_work_tree()
|
||||
|
||||
# If we're here, then there are no uncommited or unstaged changes dangling around.
|
||||
# Proceed to reload .gitignore
|
||||
if [ $err = 0 ]; then
|
||||
# Remove all cached files
|
||||
git rm -r --cached .
|
||||
# If we're here, then there are no uncommited or unstaged changes dangling around.
|
||||
# Proceed to reload .gitignore
|
||||
if [ $err = 0 ]; then
|
||||
# Remove all cached files
|
||||
git rm -r --cached .
|
||||
|
||||
# Re-add everything. The changed .gitignore will be picked up here and will exclude the files
|
||||
# now blacklisted by .gitignore
|
||||
echo >&2 "Running git add ."
|
||||
git add .
|
||||
echo >&2 "Files readded. Commit your new changes now."
|
||||
fi
|
||||
# Re-add everything. The changed .gitignore will be picked up here and will exclude the files
|
||||
# now blacklisted by .gitignore
|
||||
echo >&2 "Running git add ."
|
||||
git add .
|
||||
echo >&2 "Files readded. Commit your new changes now."
|
||||
fi
|
||||
}
|
||||
|
||||
function git-changelog() {
|
||||
# ---------------------------------------------------------------
|
||||
# ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 |
|
||||
# ---------------------------------------------------------------
|
||||
about 'Creates the git changelog from one point to another by date'
|
||||
group 'git'
|
||||
example '$ git-changelog origin/master...origin/release [md|txt]'
|
||||
|
||||
if [[ "$1" != *"..."* ]]; then
|
||||
echo "Please include the valid 'diff' to make changelog"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local NEXT=$(date +%F)
|
||||
|
||||
if [[ "$2" == "md" ]]; then
|
||||
echo "# CHANGELOG $1"
|
||||
|
||||
# shellcheck disable=SC2162
|
||||
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
|
||||
echo
|
||||
echo "### $DATE"
|
||||
git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
|
||||
NEXT=$DATE
|
||||
done
|
||||
else
|
||||
echo "CHANGELOG $1"
|
||||
echo ----------------------
|
||||
|
||||
# shellcheck disable=SC2162
|
||||
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
|
||||
echo
|
||||
echo [$DATE]
|
||||
git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
|
||||
NEXT=$DATE
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
41
plugins/available/go.plugin.bash
Executable file → Normal file
41
plugins/available/go.plugin.bash
Executable file → Normal file
@@ -1,19 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'go environment variables & path configuration'
|
||||
|
||||
command -v go &>/dev/null || return
|
||||
# Load after basher and goenv
|
||||
# BASH_IT_LOAD_PRIORITY: 270
|
||||
|
||||
function _go_pathmunge_wrap() {
|
||||
IFS=':' local -a 'a=($1)'
|
||||
local i=${#a[@]}
|
||||
while [ $i -gt 0 ] ; do
|
||||
i=$(( i - 1 ))
|
||||
pathmunge "${a[i]}/bin"
|
||||
done
|
||||
}
|
||||
# Test `go version` because goenv creates shim scripts that will be found in PATH
|
||||
# but do not always resolve to a working install.
|
||||
{ _command_exists go && go version &> /dev/null; } || return 0
|
||||
|
||||
export GOROOT="${GOROOT:-$(go env GOROOT)}"
|
||||
export GOPATH="${GOPATH:-$(go env GOPATH)}"
|
||||
_go_pathmunge_wrap "${GOPATH}:${GOROOT}"
|
||||
|
||||
# $GOPATH/bin is the default location for binaries. Because GOPATH accepts a list of paths and each
|
||||
# might be managed differently, we add each path's /bin folder to PATH using pathmunge,
|
||||
# while preserving ordering.
|
||||
# e.g. GOPATH=foo:bar -> PATH=foo/bin:bar/bin
|
||||
_bash-it-gopath-pathmunge() {
|
||||
_about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended'
|
||||
_group 'go'
|
||||
if [[ -z $GOPATH ]]; then
|
||||
echo 'GOPATH empty' >&2
|
||||
return 1
|
||||
fi
|
||||
local paths i
|
||||
IFS=: read -r -a paths <<< "$GOPATH"
|
||||
i=${#paths[@]}
|
||||
while [[ $i -gt 0 ]]; do
|
||||
i=$((i - 1))
|
||||
if [[ -n "${paths[i]}" ]]; then
|
||||
pathmunge "${paths[i]}/bin"
|
||||
fi
|
||||
done
|
||||
}
|
||||
_bash-it-gopath-pathmunge
|
||||
|
||||
@@ -1,20 +1,42 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'load goenv, if you are using it'
|
||||
|
||||
# https://github.com/syndbg/goenv
|
||||
|
||||
# Load after basher
|
||||
# BASH_IT_LOAD_PRIORITY: 260
|
||||
|
||||
# Don't modify the environment if we can't find the tool:
|
||||
# - Check if in $PATH already
|
||||
# - Check if installed manually to $GOENV_ROOT
|
||||
# - Check if installed manually to $HOME
|
||||
_command_exists goenv ||
|
||||
[[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] ||
|
||||
[[ -x "$HOME/.goenv/bin/goenv" ]] ||
|
||||
return
|
||||
_command_exists goenv \
|
||||
|| [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] \
|
||||
|| [[ -x "$HOME/.goenv/bin/goenv" ]] \
|
||||
|| return 0
|
||||
|
||||
# Set GOENV_ROOT, if not already set
|
||||
export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}"
|
||||
|
||||
# Add GOENV_ROOT/bin to PATH, if that's where it's installed
|
||||
! _command_exists goenv && [[ -x "$GOENV_ROOT/bin/goenv" ]] && pathmunge "$GOENV_ROOT/bin"
|
||||
if ! _command_exists goenv && [[ -x "$GOENV_ROOT/bin/goenv" ]]; then
|
||||
pathmunge "$GOENV_ROOT/bin"
|
||||
fi
|
||||
|
||||
# Initialize goenv
|
||||
eval "$(goenv init - bash)"
|
||||
|
||||
# If moving to a directory with a goenv version set, reload the shell
|
||||
# to ensure the shell environment matches expectations.
|
||||
_bash-it-goenv-preexec() {
|
||||
export GOENV_OLD_VERSION="$(goenv version-name)"
|
||||
}
|
||||
_bash-it-goenv-precmd() {
|
||||
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then
|
||||
exec env -u PATH -u GOROOT -u GOPATH -u GOENV_OLD_VERSION "${0/-/}" --login
|
||||
fi
|
||||
unset GOENV_OLD_VERSION
|
||||
}
|
||||
preexec_functions+=(_bash-it-goenv-preexec)
|
||||
precmd_functions+=(_bash-it-goenv-precmd)
|
||||
|
||||
10
plugins/available/history-search.plugin.bash
Normal file
10
plugins/available/history-search.plugin.bash
Normal file
@@ -0,0 +1,10 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'search history using the prefix already entered'
|
||||
|
||||
# enter a few characters and press UpArrow/DownArrow
|
||||
# to search backwards/forwards through the history
|
||||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
||||
bind '"\e[A":history-search-backward'
|
||||
bind '"\e[B":history-search-forward'
|
||||
fi
|
||||
10
plugins/available/history-substring-search.plugin.bash
Normal file
10
plugins/available/history-substring-search.plugin.bash
Normal file
@@ -0,0 +1,10 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'search history using the substring already entered'
|
||||
|
||||
# enter a few characters and press UpArrow/DownArrow
|
||||
# to search backwards/forwards through the history
|
||||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
||||
bind '"\e[A":history-substring-search-backward'
|
||||
bind '"\e[B":history-substring-search-forward'
|
||||
fi
|
||||
@@ -1,9 +1,39 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'history manipulation'
|
||||
# enter a few characters and press UpArrow/DownArrow
|
||||
# to search backwards/forwards through the history
|
||||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]
|
||||
then
|
||||
bind '"[A":history-search-backward'
|
||||
bind '"[B":history-search-forward'
|
||||
fi
|
||||
about-plugin 'improve history handling with sane defaults'
|
||||
|
||||
# append to bash_history if Terminal.app quits
|
||||
shopt -s histappend
|
||||
|
||||
# erase duplicates; alternative option: export HISTCONTROL=ignoredups
|
||||
export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
|
||||
|
||||
# resize history to 100x the default (500)
|
||||
export HISTSIZE=${HISTSIZE:-50000}
|
||||
|
||||
top-history() {
|
||||
about 'print the name and count of the most commonly run tools'
|
||||
|
||||
if [[ -n $HISTTIMEFORMAT ]]; then
|
||||
# To parse history we need a predictable format, which HISTTIMEFORMAT
|
||||
# gets in the way of. So we unset it and set a trap to guarantee the
|
||||
# user's environment returns to normal even if the pipeline below fails.
|
||||
# shellcheck disable=SC2064
|
||||
trap "export HISTTIMEFORMAT='$HISTTIMEFORMAT'" RETURN
|
||||
unset HISTTIMEFORMAT
|
||||
fi
|
||||
|
||||
history \
|
||||
| awk '{
|
||||
a[$2]++
|
||||
}END{
|
||||
for(i in a)
|
||||
printf("%s\t%s\n", a[i], i)
|
||||
}' \
|
||||
| sort --reverse --numeric-sort \
|
||||
| head \
|
||||
| column \
|
||||
--table \
|
||||
--table-columns 'Command Count,Command Name' \
|
||||
--output-separator ' | '
|
||||
}
|
||||
|
||||
@@ -1,30 +1,33 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'automatically set your xterm title with host and location info'
|
||||
|
||||
|
||||
_short-dirname () {
|
||||
local dir_name=`dirs +0`
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ ${#dir_name} -gt 8 ] && echo ${dir_name##*/} || echo $dir_name
|
||||
_short-dirname() {
|
||||
local dir_name=$(dirs +0)
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}"
|
||||
}
|
||||
|
||||
_short-command () {
|
||||
local input_command="$@"
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ ${#input_command} -gt 8 ] && echo ${input_command%% *} || echo $input_command
|
||||
_short-command() {
|
||||
local input_command="$*"
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}"
|
||||
}
|
||||
|
||||
set_xterm_title () {
|
||||
local title="$1"
|
||||
echo -ne "\033]0;$title\007"
|
||||
set_xterm_title() {
|
||||
local title="$1"
|
||||
echo -ne "\033]0;$title\007"
|
||||
}
|
||||
|
||||
precmd () {
|
||||
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} `_short-dirname` $PROMPTCHAR"
|
||||
precmd_xterm_title() {
|
||||
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR"
|
||||
}
|
||||
|
||||
preexec () {
|
||||
set_xterm_title "`_short-command $1` {`_short-dirname`} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||
preexec_xterm_title() {
|
||||
set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||
}
|
||||
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*) preexec_install;;
|
||||
xterm* | rxvt*)
|
||||
precmd_functions+=(precmd_xterm_title)
|
||||
preexec_functions+=(preexec_xterm_title)
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
BASH_IT_LOG_PREFIX="core: reloader: "
|
||||
pushd "${BASH_IT}" >/dev/null || exit 1
|
||||
|
||||
function _set-prefix-based-on-path()
|
||||
{
|
||||
@@ -9,7 +8,7 @@ function _set-prefix-based-on-path()
|
||||
BASH_IT_LOG_PREFIX="$extension: $filename: "
|
||||
}
|
||||
|
||||
if [ "$1" != "skip" ] && [ -d "./enabled" ]; then
|
||||
if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
|
||||
_bash_it_config_type=""
|
||||
|
||||
case $1 in
|
||||
@@ -20,7 +19,7 @@ if [ "$1" != "skip" ] && [ -d "./enabled" ]; then
|
||||
_log_debug "Loading all enabled components..." ;;
|
||||
esac
|
||||
|
||||
for _bash_it_config_file in $(sort <(compgen -G "./enabled/*${_bash_it_config_type}.bash")); do
|
||||
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do
|
||||
if [ -e "${_bash_it_config_file}" ]; then
|
||||
_set-prefix-based-on-path "${_bash_it_config_file}"
|
||||
_log_debug "Loading component..."
|
||||
@@ -32,12 +31,12 @@ if [ "$1" != "skip" ] && [ -d "./enabled" ]; then
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "${2}" ] && [ -d "${2}/enabled" ]; then
|
||||
if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
|
||||
case $2 in
|
||||
aliases|completion|plugins)
|
||||
_log_warning "Using legacy enabling for $2, please update your bash-it version and migrate"
|
||||
for _bash_it_config_file in $(sort <(compgen -G "./${2}/enabled/*.bash")); do
|
||||
if [ -e "$_bash_it_config_file" ]; then
|
||||
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")); do
|
||||
if [[ -e "$_bash_it_config_file" ]]; then
|
||||
_set-prefix-based-on-path "${_bash_it_config_file}"
|
||||
_log_debug "Loading component..."
|
||||
# shellcheck source=/dev/null
|
||||
@@ -51,4 +50,3 @@ fi
|
||||
|
||||
unset _bash_it_config_file
|
||||
unset _bash_it_config_type
|
||||
popd >/dev/null || exit 1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
function local_setup {
|
||||
setup_test_fixture
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../completion/available/bash-it.completion
|
||||
|
||||
function local_setup {
|
||||
|
||||
0
test/fixtures/plugin/xterm/files/arg0
vendored
Normal file
0
test/fixtures/plugin/xterm/files/arg0
vendored
Normal file
0
test/fixtures/plugin/xterm/files/arg1
vendored
Normal file
0
test/fixtures/plugin/xterm/files/arg1
vendored
Normal file
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
# Determine which config file to use based on OS.
|
||||
case $OSTYPE in
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
# Determine which config file to use based on OS.
|
||||
case $OSTYPE in
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
@test "lib composure: composure_keywords()" {
|
||||
run composure_keywords
|
||||
@test "lib composure: _composure_keywords()" {
|
||||
run _composure_keywords
|
||||
assert_output "about author example group param version"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/log
|
||||
load ../../lib/utilities
|
||||
load ../../lib/search
|
||||
@@ -69,6 +69,11 @@ function local_setup {
|
||||
assert_line -n 0 ""
|
||||
}
|
||||
|
||||
@test "helpers: bash-it help plugins" {
|
||||
run bash-it help plugins
|
||||
assert_line -n 1 "base:"
|
||||
}
|
||||
|
||||
@test "helpers: bash-it help list aliases without any aliases enabled" {
|
||||
run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash"
|
||||
assert_line -n 0 "ag:"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/appearance
|
||||
load ../../plugins/available/base.plugin
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/log
|
||||
load ../../lib/helpers
|
||||
load ../../lib/utilities
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/helpers
|
||||
load ../../lib/utilities
|
||||
load ../../lib/search
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/log
|
||||
load ../../lib/helpers
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../plugins/available/base.plugin
|
||||
|
||||
@test 'plugins base: ips()' {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
|
||||
47
test/plugins/cmd-returned-notify.plugin.bats
Normal file
47
test/plugins/cmd-returned-notify.plugin.bats
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/helpers
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
load ../../plugins/available/cmd-returned-notify.plugin
|
||||
|
||||
@test "plugins cmd-returned-notify: notify after elapsed time" {
|
||||
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0
|
||||
export LAST_COMMAND_TIME=$(date +%s)
|
||||
sleep 1
|
||||
run precmd_return_notification
|
||||
assert_success
|
||||
assert_output $'\a'
|
||||
}
|
||||
|
||||
@test "plugins cmd-returned-notify: do not notify before elapsed time" {
|
||||
export NOTIFY_IF_COMMAND_RETURNS_AFTER=10
|
||||
export LAST_COMMAND_TIME=$(date +%s)
|
||||
sleep 1
|
||||
run precmd_return_notification
|
||||
assert_success
|
||||
assert_output $''
|
||||
}
|
||||
|
||||
@test "plugins cmd-returned-notify: preexec no output" {
|
||||
export LAST_COMMAND_TIME=
|
||||
run preexec_return_notification
|
||||
assert_success
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "plugins cmd-returned-notify: preexec no output env set" {
|
||||
export LAST_COMMAND_TIME=$(date +%s)
|
||||
run preexec_return_notification
|
||||
assert_failure
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "plugins cmd-returned-notify: preexec set LAST_COMMAND_TIME" {
|
||||
export LAST_COMMAND_TIME=
|
||||
assert_equal "${LAST_COMMAND_TIME}" ""
|
||||
NOW=$(date +%s)
|
||||
preexec_return_notification
|
||||
assert_equal "${LAST_COMMAND_TIME}" "${NOW}"
|
||||
}
|
||||
@@ -2,59 +2,53 @@
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/helpers
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
@test 'ensure _go_pathmunge_wrap is defined' {
|
||||
@test 'ensure _bash-it-gopath-pathmunge is defined' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
load ../../plugins/available/go.plugin
|
||||
run type -t _go_pathmunge_wrap
|
||||
run type -t _bash-it-gopath-pathmunge
|
||||
assert_line 'function'
|
||||
}
|
||||
|
||||
@test 'plugins go: single entry in GOPATH' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: single entry in GOPATH, with space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: single entry in GOPATH, with escaped space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo\ bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo\ bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo:/bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH, with space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo:/foo bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/foo bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo:/foo\ bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/foo\ bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo\ bar/bin"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/helpers
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../plugins/available/ruby.plugin
|
||||
|
||||
function local_setup {
|
||||
|
||||
54
test/plugins/xterm.plugin.bats
Normal file
54
test/plugins/xterm.plugin.bats
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/helpers
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
load ../../plugins/available/xterm.plugin
|
||||
|
||||
function local_setup {
|
||||
setup_test_fixture
|
||||
|
||||
# Copy the test fixture to the Bash-it folder
|
||||
if _command_exists rsync; then
|
||||
rsync -a "$BASH_IT/test/fixtures/plugin/xterm/" "$BASH_IT/"
|
||||
else
|
||||
find "$BASH_IT/test/fixtures/plugin/xterm" \
|
||||
-mindepth 1 -maxdepth 1 \
|
||||
-exec cp -r {} "$BASH_IT/" \;
|
||||
fi
|
||||
}
|
||||
|
||||
@test "plugins xterm: shorten command output" {
|
||||
export SHORT_TERM_LINE=true
|
||||
run _short-command ${BASH_IT}/test/fixtures/plugin/xterm/files/*
|
||||
assert_success
|
||||
assert_output ${BASH_IT}/test/fixtures/plugin/xterm/files/arg0
|
||||
}
|
||||
|
||||
@test "plugins xterm: full command output" {
|
||||
export SHORT_TERM_LINE=false
|
||||
run _short-command ${BASH_IT}/test/fixtures/plugin/xterm/files/*
|
||||
assert_success
|
||||
assert_output "$(echo ${BASH_IT}/test/fixtures/plugin/xterm/files/*)"
|
||||
}
|
||||
|
||||
@test "plugins xterm: shorten dirname output" {
|
||||
export SHORT_TERM_LINE=true
|
||||
run _short-dirname
|
||||
assert_success
|
||||
assert_output "$(basename $PWD)"
|
||||
}
|
||||
|
||||
@test "plugins xterm: full dirname output" {
|
||||
export SHORT_TERM_LINE=false
|
||||
run _short-dirname
|
||||
assert_success
|
||||
assert_output $PWD
|
||||
}
|
||||
|
||||
@test "plugins xterm: set xterm title" {
|
||||
run set_xterm_title title
|
||||
assert_success
|
||||
assert_output $'\033]0;title\007'
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
#!/usr/bin/env bats
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
|
||||
unset BASH_IT_THEME
|
||||
unset GIT_HOSTING
|
||||
unset NGINX_PATH
|
||||
@@ -16,12 +19,15 @@ load "${TEST_DEPS_DIR}/bats-support/load.bash"
|
||||
load "${TEST_DEPS_DIR}/bats-assert/load.bash"
|
||||
load "${TEST_DEPS_DIR}/bats-file/load.bash"
|
||||
|
||||
# support 'plumbing' metadata
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
local_setup() {
|
||||
true
|
||||
true
|
||||
}
|
||||
|
||||
local_teardown() {
|
||||
true
|
||||
true
|
||||
}
|
||||
|
||||
# This function sets up a local test fixture, i.e. a completely
|
||||
@@ -29,71 +35,70 @@ local_teardown() {
|
||||
# messing with your own Bash-it source directory.
|
||||
# If you need this, call it in your .bats file's `local_setup` function.
|
||||
setup_test_fixture() {
|
||||
mkdir -p "$BASH_IT"
|
||||
lib_directory="$(cd "$(dirname "$0")" && pwd)"
|
||||
local src_topdir="$lib_directory/../../../.."
|
||||
mkdir -p "$BASH_IT"
|
||||
lib_directory="$(cd "$(dirname "$0")" && pwd)"
|
||||
local src_topdir="$lib_directory/../../../.."
|
||||
|
||||
if command -v rsync &> /dev/null
|
||||
then
|
||||
# Use rsync to copy Bash-it to the temp folder
|
||||
rsync -qavrKL -d --delete-excluded --exclude=.git --exclude=enabled "$src_topdir" "$BASH_IT"
|
||||
else
|
||||
rm -rf "$BASH_IT"
|
||||
mkdir -p "$BASH_IT"
|
||||
if command -v rsync &> /dev/null; then
|
||||
# Use rsync to copy Bash-it to the temp folder
|
||||
rsync -qavrKL -d --delete-excluded --exclude=.git --exclude=enabled "$src_topdir" "$BASH_IT"
|
||||
else
|
||||
rm -rf "$BASH_IT"
|
||||
mkdir -p "$BASH_IT"
|
||||
|
||||
find "$src_topdir" \
|
||||
-mindepth 1 -maxdepth 1 \
|
||||
-not -name .git \
|
||||
-exec cp -r {} "$BASH_IT" \;
|
||||
fi
|
||||
find "$src_topdir" \
|
||||
-mindepth 1 -maxdepth 1 \
|
||||
-not -name .git \
|
||||
-exec cp -r {} "$BASH_IT" \;
|
||||
fi
|
||||
|
||||
rm -rf "$BASH_IT"/enabled
|
||||
rm -rf "$BASH_IT"/aliases/enabled
|
||||
rm -rf "$BASH_IT"/completion/enabled
|
||||
rm -rf "$BASH_IT"/plugins/enabled
|
||||
rm -rf "$BASH_IT"/enabled
|
||||
rm -rf "$BASH_IT"/aliases/enabled
|
||||
rm -rf "$BASH_IT"/completion/enabled
|
||||
rm -rf "$BASH_IT"/plugins/enabled
|
||||
|
||||
mkdir -p "$BASH_IT"/enabled
|
||||
mkdir -p "$BASH_IT"/aliases/enabled
|
||||
mkdir -p "$BASH_IT"/completion/enabled
|
||||
mkdir -p "$BASH_IT"/plugins/enabled
|
||||
mkdir -p "$BASH_IT"/enabled
|
||||
mkdir -p "$BASH_IT"/aliases/enabled
|
||||
mkdir -p "$BASH_IT"/completion/enabled
|
||||
mkdir -p "$BASH_IT"/plugins/enabled
|
||||
|
||||
# Some tests use the BASH_IT_TEST_HOME variable, e.g. install/uninstall
|
||||
export BASH_IT_TEST_HOME="$TEST_TEMP_DIR"
|
||||
# Some tests use the BASH_IT_TEST_HOME variable, e.g. install/uninstall
|
||||
export BASH_IT_TEST_HOME="$TEST_TEMP_DIR"
|
||||
}
|
||||
|
||||
setup() {
|
||||
# The `temp_make` function from "bats-file" requires the tralston/bats-file fork,
|
||||
# since the original ztombol/bats-file's `temp_make` does not work on macOS.
|
||||
TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')"
|
||||
export TEST_TEMP_DIR
|
||||
# The `temp_make` function from "bats-file" requires the tralston/bats-file fork,
|
||||
# since the original ztombol/bats-file's `temp_make` does not work on macOS.
|
||||
TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')"
|
||||
export TEST_TEMP_DIR
|
||||
|
||||
export BASH_IT_TEST_DIR="${TEST_TEMP_DIR}/.bash_it"
|
||||
export BASH_IT_TEST_DIR="${TEST_TEMP_DIR}/.bash_it"
|
||||
|
||||
export BASH_IT_ROOT="${BASH_IT_TEST_DIR}/root"
|
||||
export BASH_IT=$BASH_IT_TEST_DIR
|
||||
export BASH_IT_ROOT="${BASH_IT_TEST_DIR}/root"
|
||||
export BASH_IT=$BASH_IT_TEST_DIR
|
||||
|
||||
mkdir -p -- "${BASH_IT_ROOT}"
|
||||
mkdir -p -- "${BASH_IT_ROOT}"
|
||||
|
||||
# Some tools, e.g. `git` use configuration files from the $HOME directory,
|
||||
# which interferes with our tests. The only way to keep `git` from doing this
|
||||
# seems to set HOME explicitly to a separate location.
|
||||
# Refer to https://git-scm.com/docs/git-config#FILES.
|
||||
unset XDG_CONFIG_HOME
|
||||
export HOME="${TEST_TEMP_DIR}"
|
||||
mkdir -p "${HOME}"
|
||||
# Some tools, e.g. `git` use configuration files from the $HOME directory,
|
||||
# which interferes with our tests. The only way to keep `git` from doing this
|
||||
# seems to set HOME explicitly to a separate location.
|
||||
# Refer to https://git-scm.com/docs/git-config#FILES.
|
||||
unset XDG_CONFIG_HOME
|
||||
export HOME="${TEST_TEMP_DIR}"
|
||||
mkdir -p "${HOME}"
|
||||
|
||||
# For `git` tests to run well, user name and email need to be set.
|
||||
# Refer to https://git-scm.com/docs/git-commit#_commit_information.
|
||||
# This goes to the test-specific config, due to the $HOME overridden above.
|
||||
git config --global user.name "John Doe"
|
||||
git config --global user.email "johndoe@example.com"
|
||||
# For `git` tests to run well, user name and email need to be set.
|
||||
# Refer to https://git-scm.com/docs/git-commit#_commit_information.
|
||||
# This goes to the test-specific config, due to the $HOME overridden above.
|
||||
git config --global user.name "John Doe"
|
||||
git config --global user.email "johndoe@example.com"
|
||||
|
||||
local_setup
|
||||
local_setup
|
||||
}
|
||||
|
||||
teardown() {
|
||||
local_teardown
|
||||
local_teardown
|
||||
|
||||
rm -rf "${BASH_IT_TEST_DIR}"
|
||||
temp_del "${TEST_TEMP_DIR}"
|
||||
rm -rf "${BASH_IT_TEST_DIR}"
|
||||
temp_del "${TEST_TEMP_DIR}"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/log
|
||||
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/log
|
||||
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||
load ../../lib/log
|
||||
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓"
|
||||
SCM_THEME_PROMPT_PREFIX=" |"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# vim: ft=bash ts=2 sw=2 sts=2
|
||||
#
|
||||
# agnoster's Theme - https://gist.github.com/3712874
|
||||
@@ -70,9 +70,9 @@ PROMPT_DIRTRIM=2 # bash4 and above
|
||||
######################################################################
|
||||
DEBUG=0
|
||||
debug() {
|
||||
if [[ ${DEBUG} -ne 0 ]]; then
|
||||
>&2 echo -e $*
|
||||
fi
|
||||
if [[ ${DEBUG} -ne 0 ]]; then
|
||||
echo >&2 -e "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
######################################################################
|
||||
@@ -87,178 +87,176 @@ LEFT_SUBSEG=''
|
||||
RIGHT_SUBSEG=''
|
||||
|
||||
text_effect() {
|
||||
case "$1" in
|
||||
reset) echo 0;;
|
||||
bold) echo 1;;
|
||||
underline) echo 4;;
|
||||
esac
|
||||
case "$1" in
|
||||
reset) echo 0 ;;
|
||||
bold) echo 1 ;;
|
||||
underline) echo 4 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# to add colors, see
|
||||
# http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux
|
||||
# under the "256 (8-bit) Colors" section, and follow the example for orange below
|
||||
fg_color() {
|
||||
case "$1" in
|
||||
black) echo 30;;
|
||||
red) echo 31;;
|
||||
green) echo 32;;
|
||||
yellow) echo 33;;
|
||||
blue) echo 34;;
|
||||
magenta) echo 35;;
|
||||
cyan) echo 36;;
|
||||
white) echo 37;;
|
||||
orange) echo 38\;5\;166;;
|
||||
esac
|
||||
case "$1" in
|
||||
black) echo 30 ;;
|
||||
red) echo 31 ;;
|
||||
green) echo 32 ;;
|
||||
yellow) echo 33 ;;
|
||||
blue) echo 34 ;;
|
||||
magenta) echo 35 ;;
|
||||
cyan) echo 36 ;;
|
||||
white) echo 37 ;;
|
||||
orange) echo 38\;5\;166 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
bg_color() {
|
||||
case "$1" in
|
||||
black) echo 40;;
|
||||
red) echo 41;;
|
||||
green) echo 42;;
|
||||
yellow) echo 43;;
|
||||
blue) echo 44;;
|
||||
magenta) echo 45;;
|
||||
cyan) echo 46;;
|
||||
white) echo 47;;
|
||||
orange) echo 48\;5\;166;;
|
||||
esac;
|
||||
case "$1" in
|
||||
black) echo 40 ;;
|
||||
red) echo 41 ;;
|
||||
green) echo 42 ;;
|
||||
yellow) echo 43 ;;
|
||||
blue) echo 44 ;;
|
||||
magenta) echo 45 ;;
|
||||
cyan) echo 46 ;;
|
||||
white) echo 47 ;;
|
||||
orange) echo 48\;5\;166 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# TIL: declare is global not local, so best use a different name
|
||||
# for codes (mycodes) as otherwise it'll clobber the original.
|
||||
# this changes from BASH v3 to BASH v4.
|
||||
ansi() {
|
||||
local seq
|
||||
declare -a mycodes=("${!1}")
|
||||
local seq
|
||||
declare -a mycodes=("${!1}")
|
||||
|
||||
debug "ansi: ${!1} all: $* aka ${mycodes[@]}"
|
||||
debug "ansi: ${!1} all: $* aka " "${mycodes[@]}"
|
||||
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['${seq}'m\\]'
|
||||
echo -ne '\[\033['${seq}'m\]'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['"${seq}"'m\\]'
|
||||
echo -ne '\[\033['"${seq}"'m\]'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
}
|
||||
|
||||
ansi_single() {
|
||||
echo -ne '\[\033['$1'm\]'
|
||||
echo -ne '\[\033['"$1"'m\]'
|
||||
}
|
||||
|
||||
# Begin a segment
|
||||
# Takes two arguments, background and foreground. Both can be omitted,
|
||||
# rendering default background/foreground.
|
||||
prompt_segment() {
|
||||
local bg fg
|
||||
declare -a codes
|
||||
local bg fg
|
||||
declare -a codes
|
||||
|
||||
debug "Prompting $1 $2 $3"
|
||||
debug "Prompting $1 $2 $3"
|
||||
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" $(text_effect reset))
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color $1)
|
||||
codes=("${codes[@]}" $bg)
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color $2)
|
||||
codes=("${codes[@]}" $fg)
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" "$(text_effect reset)")
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color "$1")
|
||||
codes=("${codes[@]}" "$bg")
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color "$2")
|
||||
codes=("${codes[@]}" "$fg")
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
|
||||
debug "Codes: "
|
||||
# declare -p codes
|
||||
debug "Codes: "
|
||||
# declare -p codes
|
||||
|
||||
if [[ $CURRENT_BG != NONE && $1 != $CURRENT_BG ]]; then
|
||||
declare -a intermediate=($(fg_color $CURRENT_BG) $(bg_color $1))
|
||||
debug "pre prompt " $(ansi intermediate[@])
|
||||
PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR"
|
||||
debug "post prompt " $(ansi codes[@])
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
else
|
||||
debug "no current BG, codes is $codes[@]"
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && PR="$PR$3"
|
||||
if [[ $CURRENT_BG != NONE && $1 != "$CURRENT_BG" ]]; then
|
||||
declare -a intermediate=("$(fg_color $CURRENT_BG)" "$(bg_color "$1")")
|
||||
debug "pre prompt " "$(ansi intermediate[@])"
|
||||
PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR"
|
||||
debug "post prompt " "$(ansi codes[@])"
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
else
|
||||
debug "no current BG, codes is " "${codes[@]}"
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && PR="$PR$3"
|
||||
}
|
||||
|
||||
# End the prompt, closing any open segments
|
||||
prompt_end() {
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
declare -a codes=($(text_effect reset) $(fg_color $CURRENT_BG))
|
||||
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
||||
fi
|
||||
declare -a reset=($(text_effect reset))
|
||||
PR="$PR $(ansi reset[@])"
|
||||
CURRENT_BG=''
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
declare -a codes=("$(text_effect reset)" "$(fg_color "$CURRENT_BG")")
|
||||
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
||||
fi
|
||||
declare -a reset=("$(text_effect reset)")
|
||||
PR="$PR $(ansi reset[@])"
|
||||
CURRENT_BG=''
|
||||
}
|
||||
|
||||
### virtualenv prompt
|
||||
prompt_virtualenv() {
|
||||
if [[ -n $VIRTUAL_ENV ]]; then
|
||||
color=cyan
|
||||
prompt_segment $color $PRIMARY_FG
|
||||
ve=`basename "$VIRTUAL_ENV"`
|
||||
prompt_segment $color white "$ve"
|
||||
fi
|
||||
if [[ -n $VIRTUAL_ENV ]]; then
|
||||
color=cyan
|
||||
prompt_segment $color "$PRIMARY_FG"
|
||||
ve=$(basename "$VIRTUAL_ENV")
|
||||
prompt_segment $color white "$ve"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
### Prompt components
|
||||
# Each component will draw itself, and hide itself if no information needs to be shown
|
||||
|
||||
# Context: user@hostname (who am I and where am I)
|
||||
prompt_context() {
|
||||
local user=`whoami`
|
||||
local user=$(whoami)
|
||||
|
||||
if [[ $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then
|
||||
prompt_segment black default "$user@\h"
|
||||
fi
|
||||
if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then
|
||||
prompt_segment black default "$user@\h"
|
||||
fi
|
||||
}
|
||||
|
||||
# prints history followed by HH:MM, useful for remembering what
|
||||
# we did previously
|
||||
prompt_histdt() {
|
||||
prompt_segment black default "\! [\A]"
|
||||
prompt_segment black default "\! [\A]"
|
||||
}
|
||||
|
||||
|
||||
git_status_dirty() {
|
||||
dirty=$(git status -s 2> /dev/null | tail -n 1)
|
||||
[[ -n $dirty ]] && echo " ●"
|
||||
dirty=$(git status -s 2> /dev/null | tail -n 1)
|
||||
[[ -n $dirty ]] && echo " ●"
|
||||
}
|
||||
|
||||
# Git: branch/detached head, dirty status
|
||||
prompt_git() {
|
||||
local ref dirty
|
||||
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY='±'
|
||||
dirty=$(git_status_dirty)
|
||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
|
||||
if [[ -n $dirty ]]; then
|
||||
prompt_segment yellow black
|
||||
else
|
||||
prompt_segment green black
|
||||
fi
|
||||
PR="$PR${ref/refs\/heads\// }$dirty"
|
||||
fi
|
||||
local ref dirty
|
||||
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY='±'
|
||||
dirty=$(git_status_dirty)
|
||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev | head -n1 2> /dev/null)"
|
||||
if [[ -n $dirty ]]; then
|
||||
prompt_segment yellow black
|
||||
else
|
||||
prompt_segment green black
|
||||
fi
|
||||
PR="$PR${ref/refs\/heads\// }$dirty"
|
||||
fi
|
||||
}
|
||||
|
||||
# Dir: current working directory
|
||||
prompt_dir() {
|
||||
prompt_segment blue black '\w'
|
||||
prompt_segment blue black '\w'
|
||||
}
|
||||
|
||||
# Status:
|
||||
@@ -266,13 +264,13 @@ prompt_dir() {
|
||||
# - am I root
|
||||
# - are there background jobs?
|
||||
prompt_status() {
|
||||
local symbols
|
||||
symbols=()
|
||||
[[ $RETVAL -ne 0 ]] && symbols+="$(ansi_single $(fg_color red))✘"
|
||||
[[ $UID -eq 0 ]] && symbols+="$(ansi_single $(fg_color yellow))⚡"
|
||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="$(ansi_single $(fg_color cyan))⚙"
|
||||
local symbols
|
||||
symbols=()
|
||||
[[ $RETVAL -ne 0 ]] && symbols+=("$(ansi_single "$(fg_color red)")✘")
|
||||
[[ $UID -eq 0 ]] && symbols+=("$(ansi_single "$(fg_color yellow)")⚡")
|
||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+=("$(ansi_single "$(fg_color cyan)")⚙")
|
||||
|
||||
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
|
||||
[[ -n "${symbols[*]}" ]] && prompt_segment black default "${symbols[@]}"
|
||||
}
|
||||
|
||||
######################################################################
|
||||
@@ -282,89 +280,89 @@ prompt_status() {
|
||||
# doesn't quite work per above
|
||||
|
||||
rightprompt() {
|
||||
printf "%*s" $COLUMNS "$PRIGHT"
|
||||
printf "%*s" $COLUMNS "$PRIGHT"
|
||||
}
|
||||
|
||||
# quick right prompt I grabbed to test things.
|
||||
__command_rprompt() {
|
||||
local times= n=$COLUMNS tz
|
||||
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
||||
MTV:US/Pacific TOK:Asia/Tokyo; do
|
||||
[ $n -gt 40 ] || break
|
||||
times="$times ${tz%%:*}\e[30;1m:\e[0;36;1m"
|
||||
times="$times$(TZ=${tz#*:} date +%H:%M)\e[0m"
|
||||
n=$(( $n - 10 ))
|
||||
done
|
||||
[ -z "$times" ] || printf "%${n}s$times\\r" ''
|
||||
local times=n=$COLUMNS tz
|
||||
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
||||
MTV:US/Pacific TOK:Asia/Tokyo; do
|
||||
[ "$n" -gt 40 ] || break
|
||||
times="$times ${tz%%:*}\e[30;1m:\e[0;36;1m"
|
||||
times="$times$(TZ=${tz#*:} date +%H:%M)\e[0m"
|
||||
n=$(("$n" - 10))
|
||||
done
|
||||
[ -z "$times" ] || printf "%${n}s$times\\r" ''
|
||||
}
|
||||
# PROMPT_COMMAND=__command_rprompt
|
||||
|
||||
# this doens't wrap code in \[ \]
|
||||
ansi_r() {
|
||||
local seq
|
||||
declare -a mycodes2=("${!1}")
|
||||
local seq
|
||||
declare -a mycodes2=("${!1}")
|
||||
|
||||
debug "ansi: ${!1} all: $* aka ${mycodes2[@]}"
|
||||
debug "ansi: ${!1} all: $* aka " "${mycodes2[@]}"
|
||||
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes2[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes2[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['${seq}'m\\]'
|
||||
echo -ne '\033['${seq}'m'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes2[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes2[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['"${seq}"'m\\]'
|
||||
echo -ne '\033['"${seq}"'m'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
}
|
||||
|
||||
# Begin a segment on the right
|
||||
# Takes two arguments, background and foreground. Both can be omitted,
|
||||
# rendering default background/foreground.
|
||||
prompt_right_segment() {
|
||||
local bg fg
|
||||
declare -a codes
|
||||
local bg fg
|
||||
declare -a codes
|
||||
|
||||
debug "Prompt right"
|
||||
debug "Prompting $1 $2 $3"
|
||||
debug "Prompt right"
|
||||
debug "Prompting $1 $2 $3"
|
||||
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" $(text_effect reset))
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color $1)
|
||||
codes=("${codes[@]}" $bg)
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color $2)
|
||||
codes=("${codes[@]}" $fg)
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" "$(text_effect reset)")
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color "$1")
|
||||
codes=("${codes[@]}" "$bg")
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color "$2")
|
||||
codes=("${codes[@]}" "$fg")
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
|
||||
debug "Right Codes: "
|
||||
# declare -p codes
|
||||
debug "Right Codes: "
|
||||
# declare -p codes
|
||||
|
||||
# right always has a separator
|
||||
# if [[ $CURRENT_RBG != NONE && $1 != $CURRENT_RBG ]]; then
|
||||
# $CURRENT_RBG=
|
||||
# fi
|
||||
declare -a intermediate2=($(fg_color $1) $(bg_color $CURRENT_RBG) )
|
||||
# PRIGHT="$PRIGHT---"
|
||||
debug "pre prompt " $(ansi_r intermediate2[@])
|
||||
PRIGHT="$PRIGHT$(ansi_r intermediate2[@])$RIGHT_SEPARATOR"
|
||||
debug "post prompt " $(ansi_r codes[@])
|
||||
PRIGHT="$PRIGHT$(ansi_r codes[@]) "
|
||||
# else
|
||||
# debug "no current BG, codes is $codes[@]"
|
||||
# PRIGHT="$PRIGHT$(ansi codes[@]) "
|
||||
# fi
|
||||
CURRENT_RBG=$1
|
||||
[[ -n $3 ]] && PRIGHT="$PRIGHT$3"
|
||||
# right always has a separator
|
||||
# if [[ $CURRENT_RBG != NONE && $1 != $CURRENT_RBG ]]; then
|
||||
# $CURRENT_RBG=
|
||||
# fi
|
||||
declare -a intermediate2=("$(fg_color "$1")" "$(bg_color $CURRENT_RBG)")
|
||||
# PRIGHT="$PRIGHT---"
|
||||
debug "pre prompt " "$(ansi_r intermediate2[@])"
|
||||
PRIGHT="$PRIGHT$(ansi_r intermediate2[@])$RIGHT_SEPARATOR"
|
||||
debug "post prompt " "$(ansi_r codes[@])"
|
||||
PRIGHT="$PRIGHT$(ansi_r codes[@]) "
|
||||
# else
|
||||
# debug "no current BG, codes is $codes[@]"
|
||||
# PRIGHT="$PRIGHT$(ansi codes[@]) "
|
||||
# fi
|
||||
CURRENT_RBG=$1
|
||||
[[ -n $3 ]] && PRIGHT="$PRIGHT$3"
|
||||
}
|
||||
|
||||
######################################################################
|
||||
@@ -385,22 +383,22 @@ prompt_right_segment() {
|
||||
# 'dirtrack-filter-out-pwd-prompt t t)))
|
||||
|
||||
prompt_emacsdir() {
|
||||
# no color or other setting... this will be deleted per above
|
||||
PR="DIR \w DIR$PR"
|
||||
# no color or other setting... this will be deleted per above
|
||||
PR="DIR \w DIR$PR"
|
||||
}
|
||||
|
||||
######################################################################
|
||||
## Main prompt
|
||||
|
||||
build_prompt() {
|
||||
[[ ! -z ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
||||
prompt_status
|
||||
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
|
||||
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
||||
prompt_virtualenv
|
||||
prompt_dir
|
||||
prompt_git
|
||||
prompt_end
|
||||
[[ -n ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
||||
prompt_status
|
||||
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
|
||||
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
||||
prompt_virtualenv
|
||||
prompt_dir
|
||||
prompt_git
|
||||
prompt_end
|
||||
}
|
||||
|
||||
# from orig...
|
||||
@@ -409,16 +407,16 @@ build_prompt() {
|
||||
# use that.
|
||||
|
||||
set_bash_prompt() {
|
||||
RETVAL=$?
|
||||
PR=""
|
||||
PRIGHT=""
|
||||
CURRENT_BG=NONE
|
||||
PR="$(ansi_single $(text_effect reset))"
|
||||
build_prompt
|
||||
RETVAL=$?
|
||||
PR=""
|
||||
PRIGHT=""
|
||||
CURRENT_BG=NONE
|
||||
PR="$(ansi_single "$(text_effect reset)")"
|
||||
build_prompt
|
||||
|
||||
# uncomment below to use right prompt
|
||||
# PS1='\[$(tput sc; printf "%*s" $COLUMNS "$PRIGHT"; tput rc)\]'$PR
|
||||
PS1=$PR
|
||||
# uncomment below to use right prompt
|
||||
# PS1='\[$(tput sc; printf "%*s" $COLUMNS "$PRIGHT"; tput rc)\]'$PR
|
||||
PS1=$PR
|
||||
}
|
||||
|
||||
PROMPT_COMMAND=set_bash_prompt
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Atomic Bash Prompt for Bash-it
|
||||
# By lfelipe base on the theme brainy of MunifTanjim
|
||||
@@ -28,79 +28,79 @@ Face="\342\230\273"
|
||||
#############
|
||||
|
||||
____atomic_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+=""
|
||||
ifs_old="${IFS}"
|
||||
IFS="|"
|
||||
read -r -a args <<< "$@"
|
||||
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+=""
|
||||
}
|
||||
|
||||
____atomic_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 ))
|
||||
ifs_old="${IFS}"
|
||||
IFS="|"
|
||||
read -r -a args <<< "$@"
|
||||
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))
|
||||
}
|
||||
|
||||
____atomic_bottom_parse() {
|
||||
ifs_old="${IFS}"
|
||||
IFS="|"
|
||||
args=( $1 )
|
||||
IFS="${ifs_old}"
|
||||
_BOTTOM+="${args[0]}${args[1]}"
|
||||
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
|
||||
ifs_old="${IFS}"
|
||||
IFS="|"
|
||||
read -r -a args <<< "$@"
|
||||
IFS="${ifs_old}"
|
||||
_BOTTOM+="${args[0]}${args[1]}"
|
||||
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
|
||||
}
|
||||
|
||||
____atomic_top() {
|
||||
_TOP_LEFT=""
|
||||
_TOP_RIGHT=""
|
||||
__TOP_RIGHT_LEN=0
|
||||
__SEG_AT_RIGHT=0
|
||||
_TOP_LEFT=""
|
||||
_TOP_RIGHT=""
|
||||
__TOP_RIGHT_LEN=0
|
||||
__SEG_AT_RIGHT=0
|
||||
|
||||
for seg in ${___ATOMIC_TOP_LEFT}; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_top_left_parse "${info}"
|
||||
done
|
||||
for seg in ${___ATOMIC_TOP_LEFT}; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_top_left_parse "${info}"
|
||||
done
|
||||
|
||||
___cursor_right="\e[500C"
|
||||
_TOP_LEFT+="${___cursor_right}"
|
||||
___cursor_right="\e[500C"
|
||||
_TOP_LEFT+="${___cursor_right}"
|
||||
|
||||
for seg in ${___ATOMIC_TOP_RIGHT}; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_top_right_parse "${info}"
|
||||
done
|
||||
for seg in ${___ATOMIC_TOP_RIGHT}; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_top_right_parse "${info}"
|
||||
done
|
||||
|
||||
[ $__TOP_RIGHT_LEN -gt 0 ] && __TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN - 0 ))
|
||||
___cursor_adjust="\e[${__TOP_RIGHT_LEN}D"
|
||||
_TOP_LEFT+="${___cursor_adjust}"
|
||||
[ $__TOP_RIGHT_LEN -gt 0 ] && __TOP_RIGHT_LEN=$((__TOP_RIGHT_LEN - 0))
|
||||
___cursor_adjust="\e[${__TOP_RIGHT_LEN}D"
|
||||
_TOP_LEFT+="${___cursor_adjust}"
|
||||
|
||||
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
|
||||
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
|
||||
}
|
||||
|
||||
____atomic_bottom() {
|
||||
_BOTTOM=""
|
||||
for seg in $___ATOMIC_BOTTOM; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_bottom_parse "${info}"
|
||||
done
|
||||
printf "\n%s" "${_BOTTOM}"
|
||||
_BOTTOM=""
|
||||
for seg in $___ATOMIC_BOTTOM; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_bottom_parse "${info}"
|
||||
done
|
||||
printf "\n%s" "${_BOTTOM}"
|
||||
}
|
||||
|
||||
##############
|
||||
@@ -108,97 +108,97 @@ ____atomic_bottom() {
|
||||
##############
|
||||
|
||||
___atomic_prompt_user_info() {
|
||||
color=$white
|
||||
box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}"
|
||||
info="${IYellow}\u${IRed}@${IGreen}\h"
|
||||
color=$white
|
||||
box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}"
|
||||
info="${IYellow}\u${IRed}@${IGreen}\h"
|
||||
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_dir() {
|
||||
color=${IRed}
|
||||
box="[|]${normal}"
|
||||
info="\w"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
color=${IRed}
|
||||
box="[|]${normal}"
|
||||
info="\w"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_scm() {
|
||||
[ "${THEME_SHOW_SCM}" != "true" ] && return
|
||||
color=$bold_green
|
||||
box="${Line}[${IWhite}$(scm_char)] "
|
||||
info="$(scm_prompt_info)"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
[ "${THEME_SHOW_SCM}" != "true" ] && return
|
||||
color=$bold_green
|
||||
box="${Line}[${IWhite}$(scm_char)] "
|
||||
info="$(scm_prompt_info)"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_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}"
|
||||
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
|
||||
color=$bold_yellow
|
||||
box="[|]"
|
||||
info="$(python_version_prompt)"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_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}"
|
||||
[ "${THEME_SHOW_RUBY}" != "true" ] && return
|
||||
color=$bold_white
|
||||
box="[|]"
|
||||
info="rb-$(ruby_version_prompt)"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_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}"
|
||||
[ "${THEME_SHOW_TODO}" != "true" ] \
|
||||
|| [ -z "$(which todo.sh)" ] && return
|
||||
color=$bold_white
|
||||
box="[|]"
|
||||
info="t:$(todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }')"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_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_white}" "${box}"
|
||||
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
|
||||
color=$THEME_CLOCK_COLOR
|
||||
box="[|]"
|
||||
info="$(date +"${THEME_CLOCK_FORMAT}")"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_battery() {
|
||||
! _command_exists battery_percentage ||
|
||||
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
|
||||
[ "$(battery_percentage)" = "no" ] && return
|
||||
! _command_exists battery_percentage \
|
||||
|| [ "${THEME_SHOW_BATTERY}" != "true" ] \
|
||||
|| [ "$(battery_percentage)" = "no" ] && return
|
||||
|
||||
batp=$(battery_percentage)
|
||||
if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then
|
||||
color=$bold_green
|
||||
elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then
|
||||
color=$bold_yellow
|
||||
elif [ "$batp" -eq 25 ] || [ "$batp" -lt 25 ]; then
|
||||
color=$IRed
|
||||
fi
|
||||
box="[|]"
|
||||
ac_adapter_connected && info="+"
|
||||
ac_adapter_disconnected && info="-"
|
||||
info+=$batp
|
||||
[ "$batp" -eq 100 ] || [ "$batp" -gt 100 ] && info="AC"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
batp=$(battery_percentage)
|
||||
if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then
|
||||
color=$bold_green
|
||||
elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then
|
||||
color=$bold_yellow
|
||||
elif [ "$batp" -eq 25 ] || [ "$batp" -lt 25 ]; then
|
||||
color=$IRed
|
||||
fi
|
||||
box="[|]"
|
||||
ac_adapter_connected && info="+"
|
||||
ac_adapter_disconnected && info="-"
|
||||
info+=$batp
|
||||
[ "$batp" -eq 100 ] || [ "$batp" -gt 100 ] && info="AC"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_exitcode() {
|
||||
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
|
||||
color=$bold_purple
|
||||
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
|
||||
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
|
||||
color=$bold_purple
|
||||
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
|
||||
}
|
||||
|
||||
___atomic_prompt_char() {
|
||||
color=$white
|
||||
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}"
|
||||
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
|
||||
if sudo -vn 1>/dev/null 2>&1; then
|
||||
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1_SUDO}"
|
||||
fi
|
||||
fi
|
||||
printf "%s|%s" "${color}" "${prompt_char}"
|
||||
color=$white
|
||||
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}"
|
||||
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
|
||||
if sudo -vn 1> /dev/null 2>&1; then
|
||||
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1_SUDO}"
|
||||
fi
|
||||
fi
|
||||
printf "%s|%s" "${color}" "${prompt_char}"
|
||||
}
|
||||
|
||||
#########
|
||||
@@ -206,54 +206,54 @@ ___atomic_prompt_char() {
|
||||
#########
|
||||
|
||||
__atomic_show() {
|
||||
typeset _seg=${1:-}
|
||||
shift
|
||||
export THEME_SHOW_${_seg}=true
|
||||
typeset _seg=${1:-}
|
||||
shift
|
||||
export "THEME_SHOW_${_seg}"=true
|
||||
}
|
||||
|
||||
__atomic_hide() {
|
||||
typeset _seg=${1:-}
|
||||
shift
|
||||
export THEME_SHOW_${_seg}=false
|
||||
typeset _seg=${1:-}
|
||||
shift
|
||||
export "THEME_SHOW_${_seg}"=false
|
||||
}
|
||||
|
||||
_atomic_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
|
||||
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 | hide)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${segments}" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPREPLY=( $(compgen -W "${actions}" -- "${cur}") )
|
||||
return 0
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${actions}" -- "${cur}"))
|
||||
return 0
|
||||
}
|
||||
|
||||
atomic() {
|
||||
typeset action=${1:-}
|
||||
shift
|
||||
typeset segs=${*:-}
|
||||
typeset func
|
||||
case $action in
|
||||
show)
|
||||
func=__atomic_show;;
|
||||
hide)
|
||||
func=__atomic_hide;;
|
||||
esac
|
||||
for seg in ${segs}; do
|
||||
seg=$(printf "%s" "${seg}" | tr '[:lower:]' '[:upper:]')
|
||||
$func "${seg}"
|
||||
done
|
||||
typeset action=${1:-}
|
||||
shift
|
||||
typeset segs=${*:-}
|
||||
typeset func
|
||||
case $action in
|
||||
show)
|
||||
func=__atomic_show
|
||||
;;
|
||||
hide)
|
||||
func=__atomic_hide
|
||||
;;
|
||||
esac
|
||||
for seg in ${segs}; do
|
||||
seg=$(printf "%s" "${seg}" | tr '[:lower:]' '[:upper:]')
|
||||
$func "${seg}"
|
||||
done
|
||||
}
|
||||
|
||||
complete -F _atomic_completion atomic
|
||||
@@ -302,19 +302,19 @@ ___ATOMIC_BOTTOM=${___ATOMIC_BOTTOM:-"char"}
|
||||
############
|
||||
|
||||
__atomic_ps1() {
|
||||
printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}"
|
||||
printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}"
|
||||
}
|
||||
|
||||
__atomic_ps2() {
|
||||
color=$bold_white
|
||||
printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}"
|
||||
color=$bold_white
|
||||
printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}"
|
||||
}
|
||||
|
||||
_atomic_prompt() {
|
||||
exitcode="$?"
|
||||
exitcode="$?"
|
||||
|
||||
PS1="$(__atomic_ps1)"
|
||||
PS2="$(__atomic_ps2)"
|
||||
PS1="$(__atomic_ps1)"
|
||||
PS2="$(__atomic_ps2)"
|
||||
}
|
||||
|
||||
safe_append_prompt_command _atomic_prompt
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Axin Bash Prompt, inspired by theme "Sexy" and "Bobby"
|
||||
# thanks to them
|
||||
|
||||
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)
|
||||
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"
|
||||
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\]"
|
||||
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}"}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓"
|
||||
SCM_THEME_PROMPT_PREFIX=" |"
|
||||
@@ -13,10 +14,10 @@ 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:$(virtualenv_prompt) ${reset_color} ${yellow}\w ${green}$(scm_prompt_info)\n${reset_color}→ "
|
||||
#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:$(virtualenv_prompt) ${reset_color} ${yellow}\w ${green}$(scm_prompt_info)\n${reset_color}→ "
|
||||
}
|
||||
|
||||
safe_append_prompt_command prompt_command
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=2034,2154
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Theme custom glyphs
|
||||
SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '}
|
||||
@@ -41,71 +40,71 @@ SCM_THEME_CURRENT_USER_PREFFIX=' '
|
||||
SCM_GIT_SHOW_CURRENT_USER=false
|
||||
|
||||
function _git-uptream-remote-logo {
|
||||
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
|
||||
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
|
||||
|
||||
local remote remote_domain
|
||||
remote=$(_git-upstream-remote)
|
||||
remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}')
|
||||
local remote remote_domain
|
||||
remote=$(_git-upstream-remote)
|
||||
remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}')
|
||||
|
||||
# remove // suffix for https:// url
|
||||
remote_domain=${remote_domain//\//}
|
||||
# remove // suffix for https:// url
|
||||
remote_domain=${remote_domain//\//}
|
||||
|
||||
case $remote_domain in
|
||||
github ) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB";;
|
||||
gitlab ) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB";;
|
||||
bitbucket ) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET";;
|
||||
* ) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT";;
|
||||
esac
|
||||
case $remote_domain in
|
||||
github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;;
|
||||
gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;;
|
||||
bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;;
|
||||
*) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function git_prompt_info {
|
||||
git_prompt_vars
|
||||
echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX"
|
||||
git_prompt_vars
|
||||
echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX"
|
||||
}
|
||||
|
||||
function _exit-code {
|
||||
if [[ "$1" -ne 0 ]]; then
|
||||
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
|
||||
else
|
||||
exit_code="${bold_green}"
|
||||
fi
|
||||
if [[ "$1" -ne 0 ]]; then
|
||||
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
|
||||
else
|
||||
exit_code="${bold_green}"
|
||||
fi
|
||||
}
|
||||
|
||||
function _prompt {
|
||||
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
|
||||
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
|
||||
|
||||
command_duration=$(_command_duration)
|
||||
command_duration=$(_command_duration)
|
||||
|
||||
_exit-code exit_code
|
||||
_git-uptream-remote-logo
|
||||
_exit-code exit_code
|
||||
_git-uptream-remote-logo
|
||||
|
||||
history -a
|
||||
history -a
|
||||
|
||||
# Detect root shell
|
||||
if [ "$(whoami)" = root ]; then
|
||||
dir_color=$red
|
||||
fi
|
||||
# Detect root shell
|
||||
if [ "$(whoami)" = root ]; then
|
||||
dir_color=$red
|
||||
fi
|
||||
|
||||
# Detect ssh
|
||||
if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then
|
||||
if [ "$HOST_INFO" = long ]; then
|
||||
host="\H"
|
||||
else
|
||||
host="\h"
|
||||
fi
|
||||
ssh_info="${bold_blue}\u${bold_orange}@${cyan}$host ${bold_orange}in"
|
||||
fi
|
||||
# Detect ssh
|
||||
if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then
|
||||
if [ "$HOST_INFO" = long ]; then
|
||||
host="\H"
|
||||
else
|
||||
host="\h"
|
||||
fi
|
||||
ssh_info="${bold_blue}\u${bold_orange}@${cyan}$host ${bold_orange}in"
|
||||
fi
|
||||
|
||||
# Detect python venv
|
||||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV} "
|
||||
elif [[ -n "${VIRTUAL_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}") "
|
||||
fi
|
||||
# Detect python venv
|
||||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV} "
|
||||
elif [[ -n "${VIRTUAL_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}") "
|
||||
fi
|
||||
|
||||
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${command_duration}${exit_code}"
|
||||
[[ ${#PS1} -gt $((COLUMNS*2)) ]] && wrap_char="\\n"
|
||||
PS1="${PS1}${wrap_char}❯${normal} "
|
||||
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${command_duration}${exit_code}"
|
||||
[[ ${#PS1} -gt $((COLUMNS * 2)) ]] && wrap_char="\\n"
|
||||
PS1="${PS1}${wrap_char}❯${normal} "
|
||||
}
|
||||
|
||||
safe_append_prompt_command _prompt
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
CLOCK_CHAR_THEME_PROMPT_PREFIX=''
|
||||
CLOCK_CHAR_THEME_PROMPT_SUFFIX=''
|
||||
@@ -87,219 +87,241 @@ RBFU_THEME_PROMPT_SUFFIX='|'
|
||||
|
||||
GIT_EXE=$(which git 2> /dev/null || true)
|
||||
P4_EXE=$(which p4 2> /dev/null || true)
|
||||
HG_EXE=$(which hg 2> /dev/null || true)
|
||||
SVN_EXE=$(which svn 2> /dev/null || true)
|
||||
HG_EXE=$(which hg 2> /dev/null || true)
|
||||
SVN_EXE=$(which svn 2> /dev/null || true)
|
||||
|
||||
# Check for broken SVN exe that is caused by some versions of Xcode.
|
||||
# See https://github.com/Bash-it/bash-it/issues/1612 for more details.
|
||||
if [[ -x "$SVN_EXE" ]] ; then
|
||||
if ! "$SVN_EXE" --version > /dev/null 2>&1 ; then
|
||||
# Unset the SVN exe variable so that SVN commands are avoided.
|
||||
SVN_EXE=""
|
||||
fi
|
||||
if [[ -x "$SVN_EXE" ]]; then
|
||||
if ! "$SVN_EXE" --version > /dev/null 2>&1; then
|
||||
# Unset the SVN exe variable so that SVN commands are avoided.
|
||||
SVN_EXE=""
|
||||
fi
|
||||
fi
|
||||
|
||||
function scm {
|
||||
if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE
|
||||
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT
|
||||
elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT
|
||||
elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM=$SCM_P4
|
||||
elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG
|
||||
elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG
|
||||
elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then SCM=$SCM_SVN
|
||||
elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2>/dev/null)" ]]; then SCM=$SCM_SVN
|
||||
else SCM=$SCM_NONE
|
||||
fi
|
||||
if [[ "$SCM_CHECK" = false ]]; then
|
||||
SCM=$SCM_NONE
|
||||
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then
|
||||
SCM=$SCM_GIT
|
||||
elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then
|
||||
SCM=$SCM_GIT
|
||||
elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
|
||||
SCM=$SCM_P4
|
||||
elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then
|
||||
SCM=$SCM_HG
|
||||
elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then
|
||||
SCM=$SCM_HG
|
||||
elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then
|
||||
SCM=$SCM_SVN
|
||||
elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; 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_P4 ]]; then SCM_CHAR=$SCM_P4_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
|
||||
if [[ -z $SCM ]]; then scm; fi
|
||||
if [[ $SCM == "$SCM_GIT" ]]; then
|
||||
SCM_CHAR=$SCM_GIT_CHAR
|
||||
elif [[ $SCM == "$SCM_P4" ]]; then
|
||||
SCM_CHAR=$SCM_P4_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_P4 ]] && p4_prompt_vars && return
|
||||
[[ $SCM == $SCM_HG ]] && hg_prompt_vars && return
|
||||
[[ $SCM == $SCM_SVN ]] && svn_prompt_vars && return
|
||||
scm
|
||||
scm_prompt_char
|
||||
SCM_DIRTY=0
|
||||
SCM_STATE=''
|
||||
[[ $SCM == "$SCM_GIT" ]] && git_prompt_vars && return
|
||||
[[ $SCM == "$SCM_P4" ]] && p4_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
|
||||
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
|
||||
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=''
|
||||
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
|
||||
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_P4} ]] && p4_prompt_info && return; } || true
|
||||
{ [[ ${SCM} == ${SCM_HG} ]] && hg_prompt_info && return; } || true
|
||||
{ [[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return; } || true
|
||||
# TODO: consider adding minimal status information for hg and svn
|
||||
{ [[ ${SCM} == "${SCM_P4}" ]] && p4_prompt_info && return; } || true
|
||||
{ [[ ${SCM} == "${SCM_HG}" ]] && hg_prompt_info && return; } || true
|
||||
{ [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true
|
||||
}
|
||||
|
||||
function terraform_workspace_prompt {
|
||||
if _command_exists terraform ; then
|
||||
if [ -d .terraform ]; then
|
||||
echo -e "$(terraform workspace show 2>/dev/null)"
|
||||
fi
|
||||
fi
|
||||
if _command_exists terraform; then
|
||||
if [ -d .terraform ]; then
|
||||
echo -e "$(terraform workspace show 2> /dev/null)"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function active_gcloud_account_prompt {
|
||||
if _command_exists gcloud; then
|
||||
echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)"
|
||||
fi
|
||||
}
|
||||
|
||||
function git_prompt_minimal_info {
|
||||
SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
|
||||
SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
|
||||
|
||||
_git-hide-status && return
|
||||
_git-hide-status && return
|
||||
|
||||
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)"
|
||||
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)"
|
||||
|
||||
if [[ -n "$(_git-status | tail -n1)" ]]; then
|
||||
SCM_DIRTY=1
|
||||
SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
|
||||
fi
|
||||
if [[ -n "$(_git-status | tail -n1)" ]]; 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}"
|
||||
# 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}"
|
||||
}
|
||||
|
||||
function git_prompt_vars {
|
||||
if ${SCM_GIT_USE_GITSTATUS} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then # use faster gitstatus
|
||||
SCM_GIT_GITSTATUS_RAN=true # use this in githelpers and below to choose gitstatus output
|
||||
else
|
||||
SCM_GIT_GITSTATUS_RAN=false
|
||||
fi
|
||||
if ${SCM_GIT_USE_GITSTATUS} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then
|
||||
# we can use faster gitstatus
|
||||
# use this variable in githelpers and below to choose gitstatus output
|
||||
SCM_GIT_GITSTATUS_RAN=true
|
||||
else
|
||||
SCM_GIT_GITSTATUS_RAN=false
|
||||
fi
|
||||
|
||||
if _git-branch &> /dev/null; then
|
||||
SCM_GIT_DETACHED="false"
|
||||
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)$(_git-remote-info)"
|
||||
else
|
||||
SCM_GIT_DETACHED="true"
|
||||
if _git-branch &> /dev/null; then
|
||||
SCM_GIT_DETACHED="false"
|
||||
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)$(_git-remote-info)"
|
||||
else
|
||||
SCM_GIT_DETACHED="true"
|
||||
|
||||
local detached_prefix
|
||||
if _git-tag &> /dev/null; then
|
||||
detached_prefix=${SCM_THEME_TAG_PREFIX}
|
||||
else
|
||||
detached_prefix=${SCM_THEME_DETACHED_PREFIX}
|
||||
fi
|
||||
SCM_BRANCH="${detached_prefix}\$(_git-friendly-ref)"
|
||||
fi
|
||||
local detached_prefix
|
||||
if _git-tag &> /dev/null; then
|
||||
detached_prefix=${SCM_THEME_TAG_PREFIX}
|
||||
else
|
||||
detached_prefix=${SCM_THEME_DETACHED_PREFIX}
|
||||
fi
|
||||
SCM_BRANCH="${detached_prefix}\$(_git-friendly-ref)"
|
||||
fi
|
||||
|
||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||
commits_behind=${VCS_STATUS_COMMITS_BEHIND}
|
||||
commits_ahead=${VCS_STATUS_COMMITS_AHEAD}
|
||||
else
|
||||
IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)"
|
||||
fi
|
||||
if [[ "${commits_ahead}" -gt 0 ]]; then
|
||||
SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}"
|
||||
[[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_ahead}"
|
||||
fi
|
||||
if [[ "${commits_behind}" -gt 0 ]]; then
|
||||
SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}"
|
||||
[[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_behind}"
|
||||
fi
|
||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||
commits_behind=${VCS_STATUS_COMMITS_BEHIND}
|
||||
commits_ahead=${VCS_STATUS_COMMITS_AHEAD}
|
||||
else
|
||||
IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)"
|
||||
fi
|
||||
if [[ "${commits_ahead}" -gt 0 ]]; then
|
||||
SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}"
|
||||
[[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_ahead}"
|
||||
fi
|
||||
if [[ "${commits_behind}" -gt 0 ]]; then
|
||||
SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}"
|
||||
[[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_behind}"
|
||||
fi
|
||||
|
||||
if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then
|
||||
local stash_count
|
||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||
stash_count=${VCS_STATUS_STASHES}
|
||||
else
|
||||
stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')"
|
||||
fi
|
||||
[[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STASH_CHAR_PREFIX}${stash_count}${SCM_GIT_STASH_CHAR_SUFFIX}"
|
||||
fi
|
||||
if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then
|
||||
local stash_count
|
||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||
stash_count=${VCS_STATUS_STASHES}
|
||||
else
|
||||
stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')"
|
||||
fi
|
||||
[[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STASH_CHAR_PREFIX}${stash_count}${SCM_GIT_STASH_CHAR_SUFFIX}"
|
||||
fi
|
||||
|
||||
SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
|
||||
if ! _git-hide-status; then
|
||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||
untracked_count=${VCS_STATUS_NUM_UNTRACKED}
|
||||
unstaged_count=${VCS_STATUS_NUM_UNSTAGED}
|
||||
staged_count=${VCS_STATUS_NUM_STAGED}
|
||||
else
|
||||
IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)"
|
||||
fi
|
||||
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 ]] && SCM_BRANCH+=" ${SCM_GIT_STAGED_CHAR}${staged_count}" && SCM_DIRTY=3
|
||||
[[ "${unstaged_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2
|
||||
[[ "${untracked_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1
|
||||
fi
|
||||
SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
|
||||
fi
|
||||
fi
|
||||
SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
|
||||
if ! _git-hide-status; then
|
||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||
untracked_count=${VCS_STATUS_NUM_UNTRACKED}
|
||||
unstaged_count=${VCS_STATUS_NUM_UNSTAGED}
|
||||
staged_count=${VCS_STATUS_NUM_STAGED}
|
||||
else
|
||||
IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)"
|
||||
fi
|
||||
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 ]] && SCM_BRANCH+=" ${SCM_GIT_STAGED_CHAR}${staged_count}" && SCM_DIRTY=3
|
||||
[[ "${unstaged_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2
|
||||
[[ "${untracked_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1
|
||||
fi
|
||||
SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
|
||||
fi
|
||||
fi
|
||||
|
||||
# no if for gitstatus here, user extraction is not supported by it
|
||||
[[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)"
|
||||
# no if for gitstatus here, user extraction is not supported by it
|
||||
[[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)"
|
||||
|
||||
SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
|
||||
SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
|
||||
SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
|
||||
SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
|
||||
|
||||
SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "")
|
||||
SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo "")
|
||||
}
|
||||
|
||||
function p4_prompt_vars {
|
||||
IFS=$'\t' read -r \
|
||||
opened_count non_default_changes default_count \
|
||||
add_file_count edit_file_count delete_file_count \
|
||||
<<< "$(_p4-opened-counts)"
|
||||
if [[ "${opened_count}" -gt 0 ]]; then
|
||||
SCM_DIRTY=1
|
||||
SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
|
||||
[[ "${opened_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_OPENED_CHAR}${opened_count}"
|
||||
[[ "${non_default_changes}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_CHANGES_CHAR}${non_default_changes}"
|
||||
[[ "${default_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_DEFAULT_CHAR}${default_count}"
|
||||
else
|
||||
SCM_DIRTY=0
|
||||
SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
|
||||
fi
|
||||
IFS=$'\t' read -r \
|
||||
opened_count non_default_changes default_count \
|
||||
add_file_count edit_file_count delete_file_count \
|
||||
<<< "$(_p4-opened-counts)"
|
||||
if [[ "${opened_count}" -gt 0 ]]; then
|
||||
SCM_DIRTY=1
|
||||
SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
|
||||
[[ "${opened_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_OPENED_CHAR}${opened_count}"
|
||||
[[ "${non_default_changes}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_CHANGES_CHAR}${non_default_changes}"
|
||||
[[ "${default_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_DEFAULT_CHAR}${default_count}"
|
||||
else
|
||||
SCM_DIRTY=0
|
||||
SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
|
||||
fi
|
||||
|
||||
SCM_PREFIX=${P4_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
|
||||
SCM_SUFFIX=${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
|
||||
SCM_PREFIX=${P4_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
|
||||
SCM_SUFFIX=${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
|
||||
}
|
||||
|
||||
function svn_prompt_vars {
|
||||
if [[ -n $(svn status |head -c1 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 --show-item=url 2> /dev/null | awk -F/ '{ 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 --show-item=revision 2> /dev/null)
|
||||
if [[ -n $(svn status | head -c1 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 --show-item=url 2> /dev/null | awk -F/ '{ 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 --show-item=revision 2> /dev/null)
|
||||
}
|
||||
|
||||
# this functions returns absolute location of .hg directory if one exists
|
||||
@@ -310,268 +332,268 @@ function svn_prompt_vars {
|
||||
# - .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)
|
||||
local CURRENT_DIR=$(pwd)
|
||||
|
||||
while [ "$CURRENT_DIR" != "/" ]; do
|
||||
if [ -d "$CURRENT_DIR/.hg" ]; then
|
||||
echo "$CURRENT_DIR/.hg"
|
||||
return
|
||||
fi
|
||||
while [ "$CURRENT_DIR" != "/" ]; do
|
||||
if [ -d "$CURRENT_DIR/.hg" ]; then
|
||||
echo "$CURRENT_DIR/.hg"
|
||||
return
|
||||
fi
|
||||
|
||||
CURRENT_DIR=$(dirname $CURRENT_DIR)
|
||||
done
|
||||
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}
|
||||
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)
|
||||
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/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 -vn 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
|
||||
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 -vn 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 nvm_version_prompt {
|
||||
local node
|
||||
if declare -f -F nvm &> /dev/null; then
|
||||
node=$(nvm current 2> /dev/null)
|
||||
[[ "${node}" == "system" ]] && return
|
||||
echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}"
|
||||
fi
|
||||
local node
|
||||
if declare -f -F nvm &> /dev/null; then
|
||||
node=$(nvm current 2> /dev/null)
|
||||
[[ "${node}" == "system" ]] && return
|
||||
echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}"
|
||||
fi
|
||||
}
|
||||
|
||||
function node_version_prompt {
|
||||
echo -e "$(nvm_version_prompt)"
|
||||
echo -e "$(nvm_version_prompt)"
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
if ! chruby | grep -q '\*'; then
|
||||
ruby_version="${ruby_version} (system)"
|
||||
fi
|
||||
echo -e "${CHRUBY_THEME_PROMPT_PREFIX}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX}"
|
||||
fi
|
||||
}
|
||||
|
||||
function ruby_version_prompt {
|
||||
if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then
|
||||
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
|
||||
fi
|
||||
if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then
|
||||
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
|
||||
fi
|
||||
}
|
||||
|
||||
function k8s_context_prompt {
|
||||
echo -e "$(kubectl config current-context 2> /dev/null)"
|
||||
echo -e "$(kubectl config current-context 2> /dev/null)"
|
||||
}
|
||||
|
||||
function virtualenv_prompt {
|
||||
if [[ -n "$VIRTUAL_ENV" ]]; then
|
||||
virtualenv=`basename "$VIRTUAL_ENV"`
|
||||
echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX"
|
||||
fi
|
||||
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
|
||||
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 'NR==1{print "py-"$2;}') || return
|
||||
echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}"
|
||||
py_version=$(python --version 2>&1 | awk 'NR==1{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)"
|
||||
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 | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done))
|
||||
[[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX"
|
||||
# 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 | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; 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"}
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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-hide-status && return
|
||||
git_prompt_vars
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||
_git-hide-status && return
|
||||
git_prompt_vars
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||
}
|
||||
|
||||
function p4_prompt_info() {
|
||||
p4_prompt_vars
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}"
|
||||
p4_prompt_vars
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}"
|
||||
}
|
||||
|
||||
function svn_prompt_info {
|
||||
svn_prompt_vars
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||
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}"
|
||||
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}"
|
||||
scm_prompt_char
|
||||
echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
|
||||
}
|
||||
|
||||
function prompt_char {
|
||||
scm_char
|
||||
scm_char
|
||||
}
|
||||
|
||||
function battery_char {
|
||||
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
|
||||
echo -e "${bold_red}$(battery_percentage)%"
|
||||
fi
|
||||
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
|
||||
echo -e "${bold_red}$(battery_percentage)%"
|
||||
fi
|
||||
}
|
||||
|
||||
if ! _command_exists battery_charge ; then
|
||||
# if user has installed battery plugin, skip this...
|
||||
function battery_charge (){
|
||||
# no op
|
||||
echo -n
|
||||
}
|
||||
if ! _command_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 ! _command_exists battery_percentage ; then
|
||||
function battery_char (){
|
||||
# no op
|
||||
echo -n
|
||||
}
|
||||
if ! _command_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
|
||||
if [[ $AWS_DEFAULT_PROFILE ]]; then
|
||||
echo -e "${AWS_DEFAULT_PROFILE}"
|
||||
else
|
||||
echo -e "default"
|
||||
fi
|
||||
}
|
||||
|
||||
function __check_precmd_conflict() {
|
||||
local f
|
||||
for f in "${precmd_functions[@]}"; do
|
||||
if [[ "${f}" == "${1}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
local f
|
||||
for f in "${precmd_functions[@]}"; do
|
||||
if [[ "${f}" == "${1}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function safe_append_prompt_command {
|
||||
local prompt_re
|
||||
local prompt_re
|
||||
|
||||
if [ "${__bp_imported}" == "defined" ]; then
|
||||
# We are using bash-preexec
|
||||
if ! __check_precmd_conflict "${1}" ; then
|
||||
precmd_functions+=("${1}")
|
||||
fi
|
||||
else
|
||||
# Set OS dependent exact match regular expression
|
||||
if [[ ${OSTYPE} == darwin* ]]; then
|
||||
# macOS
|
||||
prompt_re="[[:<:]]${1}[[:>:]]"
|
||||
else
|
||||
# Linux, FreeBSD, etc.
|
||||
prompt_re="\<${1}\>"
|
||||
fi
|
||||
if [ "${__bp_imported}" == "defined" ]; then
|
||||
# We are using bash-preexec
|
||||
if ! __check_precmd_conflict "${1}"; then
|
||||
precmd_functions+=("${1}")
|
||||
fi
|
||||
else
|
||||
# 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
|
||||
fi
|
||||
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
|
||||
return
|
||||
elif [[ -z ${PROMPT_COMMAND} ]]; then
|
||||
PROMPT_COMMAND="${1}"
|
||||
else
|
||||
PROMPT_COMMAND="${1};${PROMPT_COMMAND}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function _save-and-reload-history() {
|
||||
local autosave=${1:-0}
|
||||
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
|
||||
local autosave=${1:-0}
|
||||
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
|
||||
}
|
||||
|
||||
@@ -1,80 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Detect whether a reboot 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
|
||||
if [ -n "$_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
|
||||
# Detect if connection is through SSH
|
||||
if [[ -n $SSH_CLIENT ]]; then
|
||||
printf '%s' "${lime_yellow}"
|
||||
else
|
||||
printf '%s' "${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
|
||||
case $(id -u) in
|
||||
0)
|
||||
printf '%s' "${red}"
|
||||
;;
|
||||
*)
|
||||
printf '%s' "${cyan}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
scm_prompt() {
|
||||
CHAR=$(scm_char)
|
||||
if [ $CHAR = $SCM_NONE_CHAR ]
|
||||
then
|
||||
return
|
||||
else
|
||||
echo "[$(scm_char)$(scm_prompt_info)]"
|
||||
fi
|
||||
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)\]"
|
||||
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)\]"
|
||||
light_orange="\[$(tput setaf 172)\]"
|
||||
bright_yellow="\[$(tput setaf 220)\]"
|
||||
lime_yellow="\[$(tput setaf 190)\]"
|
||||
|
||||
powder_blue="\[$(tput setaf 153)\]"
|
||||
powder_blue="\[$(tput setaf 153)\]"
|
||||
}
|
||||
|
||||
__ps_time() {
|
||||
echo "$(clock_prompt)${normal}\n"
|
||||
printf '%s' "$(clock_prompt)${normal}\n"
|
||||
}
|
||||
|
||||
function prompt_command() {
|
||||
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
|
||||
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_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_path="${yellow}\w${normal}"
|
||||
ps_scm_prompt="${light_grey}$(scm_prompt)"
|
||||
|
||||
ps_user_mark="${normal} ${normal}"
|
||||
ps_user_input="${normal}"
|
||||
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"
|
||||
# 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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
|
||||
SCM_THEME_PROMPT_PREFIX=" ${yellow}‹"
|
||||
SCM_THEME_PROMPT_SUFFIX="›${reset_color}"
|
||||
@@ -9,14 +9,14 @@ VIRTUALENV_THEME_PROMPT_SUFFIX="›${reset_color}"
|
||||
bold="\[\e[1m\]"
|
||||
|
||||
if [ ${UID} -eq 0 ]; then
|
||||
user_host="${bold_red}\u@\h${normal}${reset_color}"
|
||||
user_host="${bold_red}\u@\h${normal}${reset_color}"
|
||||
else
|
||||
user_host="${bold_green}\u@\h${normal}${reset_color}"
|
||||
user_host="${bold_green}\u@\h${normal}${reset_color}"
|
||||
fi
|
||||
|
||||
function prompt_command() {
|
||||
local current_dir=" ${bold_blue}\w${normal}${reset_color}"
|
||||
PS1="╭─${user_host}${current_dir}$(virtualenv_prompt)$(scm_prompt_info)\n╰─${bold}\\$ ${normal}"
|
||||
local current_dir=" ${bold_blue}\w${normal}${reset_color}"
|
||||
PS1="╭─${user_host}${current_dir}$(virtualenv_prompt)$(scm_prompt_info)\n╰─${bold}\\$ ${normal}"
|
||||
}
|
||||
|
||||
safe_append_prompt_command prompt_command
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user