Added shebash line and fix some issues

This commit is contained in:
Toan Nguyen 2017-03-20 19:51:00 +07:00
parent 14d571a5d5
commit ea1c9371e1
17 changed files with 207 additions and 135 deletions

16
.gitignore vendored
View File

@ -1,14 +1,14 @@
# custom files # custom files
/custom/* #/custom/
!/custom/gitkeep #!/custom/plugins/example/
!/custom/plugins/example #!/custom/example.sh
!/custom/example.sh
# temp files directories # temp files directories
/cache/* #/cache/
/log/* #/log/
!/cache/.gitkeep #!/cache/.gitkeep
!/log/.gitkeep #!/log/.gitkeep
# disabled files # disabled files
*.disabled *.disabled
.idea/

View File

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

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
function bash_stats() { function bash_stats() {
fc -l 1 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20 fc -l 1 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
} }

View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Outputs current branch info in prompt format # Outputs current branch info in prompt format
function git_prompt_info() { function git_prompt_info() {
local ref local ref

29
lib/grep.sh Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
# is x grep argument available?
grep-flag-available() {
echo | grep $1 "" >/dev/null 2>&1
}
GREP_OPTIONS=""
# color grep results
if grep-flag-available --color=auto; then
GREP_OPTIONS+=( " --color=auto" )
fi
# ignore VCS folders (if the necessary grep flags are available)
VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
if grep-flag-available --exclude-dir=.cvs; then
GREP_OPTIONS+=( " --exclude-dir=$VCS_FOLDERS" )
elif grep-flag-available --exclude=.cvs; then
GREP_OPTIONS+=( " --exclude=$VCS_FOLDERS" )
fi
# export grep settings
alias grep="grep $GREP_OPTIONS"
# clean up
unset GREP_OPTIONS
unset VCS_FOLDERS
unset -f grep-flag-available

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
shopt -s histappend # append to bash_history if Terminal.app quits shopt -s histappend # append to bash_history if Terminal.app quits
## Command history configuration ## Command history configuration

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
## jobs ## jobs
#setopt long_list_jobs #setopt long_list_jobs

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
# get the node.js version # get the node.js version
function nvm_prompt_info() { function nvm_prompt_info() {
[[ -f "$NVM_DIR/nvm.sh" ]] || return [[ -f "$NVM_DIR/nvm.sh" ]] || return

37
lib/spectrum.sh Normal file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
# A script to make using 256 colors in bash less painful.
# P.C. Shyamshankar <sykora@lucentbeing.com>
# Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
typeset -Ag FX FG BG
FX=(
reset "%{^[[00m%}"
bold "%{^[[01m%}" no-bold "%{^[[22m%}"
italic "%{^[[03m%}" no-italic "%{^[[23m%}"
underline "%{^[[04m%}" no-underline "%{^[[24m%}"
blink "%{^[[05m%}" no-blink "%{^[[25m%}"
reverse "%{^[[07m%}" no-reverse "%{^[[27m%}"
)
for color in {000..255}; do
FG[$color]="%{^[[38;5;${color}m%}"
BG[$color]="%{^[[48;5;${color}m%}"
done
OSH_SPECTRUM_TEXT=${OSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
# Show all 256 colors with color number
function spectrum_ls() {
for code in {000..255}; do
print -P -- "$code: %{$FG[$code]%}$OSH_SPECTRUM_TEXT%{$reset_color%}"
done
}
# Show all 256 colors where the background is set to specific color
function spectrum_bls() {
for code in {000..255}; do
print -P -- "$code: %{$BG[$code]%}$OSH_SPECTRUM_TEXT%{$reset_color%}"
done
}

View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash
# Check for updates on initial load... # Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
env OSH=$OSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT sh -f $OSH/tools/check_for_upgrade.sh env OSH=$OSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT bash -f $OSH/tools/check_for_upgrade.sh
fi fi
# Initializes Oh My Bash # Initializes Oh My Bash

View File

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2015, Toan Nguyen - https://nntoan.github.io
# Copyright (c) 2014, NNToan - http://about.me/nntoan
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without modification, are permitted provided # Redistribution and use in source and binary forms, with or without modification, are permitted provided
@ -45,59 +44,59 @@ GREEN="0;33m"
# main function # main function
function bm { function bm {
option="${1}" option="${1}"
case ${option} in case ${option} in
# save current directory to bookmarks [ bm -a BOOKMARK_NAME ] # save current directory to bookmarks [ bm -a BOOKMARK_NAME ]
-a) -a)
_save_bookmark "$2" _save_bookmark "$2"
;; ;;
# delete bookmark [ bm -d BOOKMARK_NAME ] # delete bookmark [ bm -d BOOKMARK_NAME ]
-d) -d)
_delete_bookmark "$2" _delete_bookmark "$2"
;; ;;
# jump to bookmark [ bm -g BOOKMARK_NAME ] # jump to bookmark [ bm -g BOOKMARK_NAME ]
-g) -g)
_goto_bookmark "$2" _goto_bookmark "$2"
;; ;;
# print bookmark [ bm -p BOOKMARK_NAME ] # print bookmark [ bm -p BOOKMARK_NAME ]
-p) -p)
_print_bookmark "$2" _print_bookmark "$2"
;; ;;
# show bookmark list [ bm -l ] # show bookmark list [ bm -l ]
-l) -l)
_list_bookmark _list_bookmark
;; ;;
# help [ bm -h ] # help [ bm -h ]
*) *)
echo 'USAGE:' echo 'USAGE:'
echo 'bm -a <bookmark_name> - Saves the current directory as "bookmark_name"' echo 'bm -a <bookmark_name> - Saves the current directory as "bookmark_name"'
echo 'bm -g <bookmark_name> - Goes (cd) to the directory associated with "bookmark_name"' echo 'bm -g <bookmark_name> - Goes (cd) to the directory associated with "bookmark_name"'
echo 'bm -p <bookmark_name> - Prints the directory associated with "bookmark_name"' echo 'bm -p <bookmark_name> - Prints the directory associated with "bookmark_name"'
echo 'bm -d <bookmark_name> - Deletes the bookmark' echo 'bm -d <bookmark_name> - Deletes the bookmark'
echo 'bm -l - Lists all available bookmarks' echo 'bm -l - Lists all available bookmarks'
kill -SIGINT $$ kill -SIGINT $$
exit 1 exit 1
;; ;;
esac esac
} }
# save current directory to bookmarks # save current directory to bookmarks
function _save_bookmark { function _save_bookmark {
_bookmark_name_valid "$@" _bookmark_name_valid "$@"
if [ -z "$exit_message" ]; then if [ -z "$exit_message" ]; then
_purge_line "$SDIRS" "export DIR_$1=" _purge_line "$SDIRS" "export DIR_$1="
CURDIR=$(echo $PWD| sed "s#^$HOME#\$HOME#g") CURDIR=$(echo $PWD| sed "s#^$HOME#\$HOME#g")
echo "export DIR_$1=\"$CURDIR\"" >> $SDIRS echo "export DIR_$1=\"$CURDIR\"" >> $SDIRS
fi fi
} }
# delete bookmark # delete bookmark
function _delete_bookmark { function _delete_bookmark {
_bookmark_name_valid "$@" _bookmark_name_valid "$@"
if [ -z "$exit_message" ]; then if [ -z "$exit_message" ]; then
_purge_line "$SDIRS" "export DIR_$1=" _purge_line "$SDIRS" "export DIR_$1="
unset "DIR_$1" unset "DIR_$1"
fi fi
} }
# jump to bookmark # jump to bookmark
@ -157,42 +156,42 @@ function _comp {
# ZSH completion command # ZSH completion command
function _compzsh { function _compzsh {
reply=($(_l)) reply=($(_l))
} }
# safe delete line from sdirs # safe delete line from sdirs
function _purge_line { function _purge_line {
if [ -s "$1" ]; then if [ -s "$1" ]; then
# safely create a temp file # safely create a temp file
t=$(mktemp -t bashmarks.XXXXXX) || exit 1 t=$(mktemp -t bashmarks.XXXXXX) || exit 1
trap "rm -f -- '$t'" EXIT trap "/bin/rm -f -- '$t'" EXIT
# purge line # purge line
sed "/$2/d" "$1" > "$t" sed "/$2/d" "$1" > "$t"
mv "$t" "$1" /bin/mv "$t" "$1"
# cleanup temp file # cleanup temp file
rm -f -- "$t" /bin/rm -f -- "$t"
trap - EXIT trap - EXIT
fi fi
} }
# bind completion command for g,p,d to _comp # bind completion command for g,p,d to _comp
if [ $ZSH_VERSION ]; then if [ $ZSH_VERSION ]; then
compctl -K _compzsh bm -g compctl -K _compzsh bm -g
compctl -K _compzsh bm -p compctl -K _compzsh bm -p
compctl -K _compzsh bm -d compctl -K _compzsh bm -d
compctl -K _compzsh g compctl -K _compzsh g
compctl -K _compzsh p compctl -K _compzsh p
compctl -K _compzsh d compctl -K _compzsh d
else else
shopt -s progcomp shopt -s progcomp
complete -F _comp bm -g complete -F _comp bm -g
complete -F _comp bm -p complete -F _comp bm -p
complete -F _comp bm -d complete -F _comp bm -d
complete -F _comp g complete -F _comp g
complete -F _comp p complete -F _comp p
complete -F _comp d complete -F _comp d
fi fi
alias s='bm -a' # Save a bookmark [bookmark_name] alias s='bm -a' # Save a bookmark [bookmark_name]

View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# #
# Description: This file holds all my BASH configurations and aliases # Description: This file holds all my BASH configurations and aliases

View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Functions # Functions
# #

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
############################---Description---################################### ############################---Description---###################################
# # # #
# Summary : Show a progress bar GUI on terminal platform # # Summary : Show a progress bar GUI on terminal platform #

View File

@ -1,68 +1,68 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Powerline theme
__powerline() { __powerline() {
# Unicode symbols # Unicode symbols
readonly PS_SYMBOL_DARWIN='' PS_SYMBOL_DARWIN=''
readonly PS_SYMBOL_LINUX='$' PS_SYMBOL_LINUX='$'
readonly PS_SYMBOL_OTHER='%' PS_SYMBOL_OTHER='%'
readonly GIT_BRANCH_SYMBOL='⑂ ' GIT_BRANCH_SYMBOL='⑂ '
readonly GIT_BRANCH_CHANGED_SYMBOL='+' GIT_BRANCH_CHANGED_SYMBOL='+'
readonly GIT_NEED_PUSH_SYMBOL='⇡' GIT_NEED_PUSH_SYMBOL='⇡'
readonly GIT_NEED_PULL_SYMBOL='⇣' GIT_NEED_PULL_SYMBOL='⇣'
# Solarized colorscheme # Solarized colorscheme
readonly FG_BASE03="\[$(tput setaf 8)\]" FG_BASE03="\[$(tput setaf 8)\]"
readonly FG_BASE02="\[$(tput setaf 0)\]" FG_BASE02="\[$(tput setaf 0)\]"
readonly FG_BASE01="\[$(tput setaf 10)\]" FG_BASE01="\[$(tput setaf 10)\]"
readonly FG_BASE00="\[$(tput setaf 11)\]" FG_BASE00="\[$(tput setaf 11)\]"
readonly FG_BASE0="\[$(tput setaf 12)\]" FG_BASE0="\[$(tput setaf 12)\]"
readonly FG_BASE1="\[$(tput setaf 14)\]" FG_BASE1="\[$(tput setaf 14)\]"
readonly FG_BASE2="\[$(tput setaf 7)\]" FG_BASE2="\[$(tput setaf 7)\]"
readonly FG_BASE3="\[$(tput setaf 15)\]" FG_BASE3="\[$(tput setaf 15)\]"
readonly BG_BASE03="\[$(tput setab 8)\]" BG_BASE03="\[$(tput setab 8)\]"
readonly BG_BASE02="\[$(tput setab 0)\]" BG_BASE02="\[$(tput setab 0)\]"
readonly BG_BASE01="\[$(tput setab 10)\]" BG_BASE01="\[$(tput setab 10)\]"
readonly BG_BASE00="\[$(tput setab 11)\]" BG_BASE00="\[$(tput setab 11)\]"
readonly BG_BASE0="\[$(tput setab 12)\]" BG_BASE0="\[$(tput setab 12)\]"
readonly BG_BASE1="\[$(tput setab 14)\]" BG_BASE1="\[$(tput setab 14)\]"
readonly BG_BASE2="\[$(tput setab 7)\]" BG_BASE2="\[$(tput setab 7)\]"
readonly BG_BASE3="\[$(tput setab 15)\]" BG_BASE3="\[$(tput setab 15)\]"
readonly FG_YELLOW="\[$(tput setaf 3)\]" FG_YELLOW="\[$(tput setaf 3)\]"
readonly FG_ORANGE="\[$(tput setaf 9)\]" FG_ORANGE="\[$(tput setaf 9)\]"
readonly FG_RED="\[$(tput setaf 1)\]" FG_RED="\[$(tput setaf 1)\]"
readonly FG_MAGENTA="\[$(tput setaf 5)\]" FG_MAGENTA="\[$(tput setaf 5)\]"
readonly FG_VIOLET="\[$(tput setaf 13)\]" FG_VIOLET="\[$(tput setaf 13)\]"
readonly FG_BLUE="\[$(tput setaf 4)\]" FG_BLUE="\[$(tput setaf 4)\]"
readonly FG_CYAN="\[$(tput setaf 6)\]" FG_CYAN="\[$(tput setaf 6)\]"
readonly FG_GREEN="\[$(tput setaf 2)\]" FG_GREEN="\[$(tput setaf 2)\]"
readonly BG_YELLOW="\[$(tput setab 3)\]" BG_YELLOW="\[$(tput setab 3)\]"
readonly BG_ORANGE="\[$(tput setab 9)\]" BG_ORANGE="\[$(tput setab 9)\]"
readonly BG_RED="\[$(tput setab 1)\]" BG_RED="\[$(tput setab 1)\]"
readonly BG_MAGENTA="\[$(tput setab 5)\]" BG_MAGENTA="\[$(tput setab 5)\]"
readonly BG_VIOLET="\[$(tput setab 13)\]" BG_VIOLET="\[$(tput setab 13)\]"
readonly BG_BLUE="\[$(tput setab 4)\]" BG_BLUE="\[$(tput setab 4)\]"
readonly BG_CYAN="\[$(tput setab 6)\]" BG_CYAN="\[$(tput setab 6)\]"
readonly BG_GREEN="\[$(tput setab 2)\]" BG_GREEN="\[$(tput setab 2)\]"
readonly DIM="\[$(tput dim)\]" DIM="\[$(tput dim)\]"
readonly REVERSE="\[$(tput rev)\]" REVERSE="\[$(tput rev)\]"
readonly RESET="\[$(tput sgr0)\]" RESET="\[$(tput sgr0)\]"
readonly BOLD="\[$(tput bold)\]" BOLD="\[$(tput bold)\]"
# what OS? # what OS?
case "$(uname)" in case "$(uname)" in
Darwin) Darwin)
readonly PS_SYMBOL=$PS_SYMBOL_DARWIN PS_SYMBOL=$PS_SYMBOL_DARWIN
;; ;;
Linux) Linux)
readonly PS_SYMBOL=$PS_SYMBOL_LINUX PS_SYMBOL=$PS_SYMBOL_LINUX
;; ;;
*) *)
readonly PS_SYMBOL=$PS_SYMBOL_OTHER PS_SYMBOL=$PS_SYMBOL_OTHER
esac esac
__git_info() { __git_info() {
@ -107,4 +107,4 @@ __powerline() {
} }
__powerline __powerline
unset __powerline unset -f __powerline

View File

@ -7,7 +7,7 @@ function _current_epoch() {
} }
function _update_osh_update() { function _update_osh_update() {
echo "LAST_EPOCH=$(_current_epoch)" >! ~/.osh-update echo "LAST_EPOCH=$(_current_epoch)" >| ~/.osh-update
} }
function _upgrade_osh() { function _upgrade_osh() {
@ -42,7 +42,7 @@ if mkdir "$OSH/log/update.lock" 2>/dev/null; then
if [ "$DISABLE_UPDATE_PROMPT" = "true" ]; then if [ "$DISABLE_UPDATE_PROMPT" = "true" ]; then
_upgrade_osh _upgrade_osh
else else
echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c" echo "[Oh My Bash] Would you like to check for updates? [Y/n]: \c"
read line read line
if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then
_upgrade_osh _upgrade_osh

View File

@ -1,3 +1,5 @@
#!/usr/bin/env bash
# Use colors, but only if connected to a terminal, and that terminal # Use colors, but only if connected to a terminal, and that terminal
# supports them. # supports them.
if which tput >/dev/null 2>&1; then if which tput >/dev/null 2>&1; then