diff --git a/README.md b/README.md index 912da87e..49f54a33 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Bash it provides a solid framework for using, developing and maintaining shell s ## Install -1. Check a clone of this repo: `git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it` +1. Check out a clone of this repo to a location of your choice, such as: `git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it` 2. Run `~/.bash_it/install.sh` (it automatically backs up your `~/.bash_profile` or `~/.bashrc`, depending on your OS) 3. Edit your modified config (`~/.bash_profile` or `~/.bashrc`) file in order to customize Bash it. 4. Check out available aliases, completions and plugins and enable the ones you want to use (see the next section for more details). diff --git a/install.sh b/install.sh index 38b5d64e..f6b24edd 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -BASH_IT="$HOME/.bash_it" +BASH_IT="$(dirname "$(readlink -f "$0")")" case $OSTYPE in darwin*) @@ -36,18 +36,19 @@ test -w "$HOME/$CONFIG_FILE" && cp -a "$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" -cp "$HOME/.bash_it/template/bash_profile.template.bash" "$HOME/$CONFIG_FILE" +cp "$BASH_IT/template/bash_profile.template.bash" "$HOME/$CONFIG_FILE" +sed -i "s|{{BASH_IT}}|$BASH_IT|" "$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 load_one() { file_type=$1 file_to_enable=$2 - [ ! -d "$BASH_IT/$file_type/enabled" ] && mkdir "$BASH_IT/${file_type}/enabled" + mkdir -p "$BASH_IT/${file_type}/enabled" dest="${BASH_IT}/${file_type}/enabled/${file_to_enable}" if [ ! -e "${dest}" ]; then - ln -s "../available/${file_to_enable}" "${dest}" + ln -sf "../available/${file_to_enable}" "${dest}" else echo "File ${dest} exists, skipping" fi @@ -89,7 +90,8 @@ else echo "" echo -e "\033[0;32mEnabling sane defaults\033[0m" load_one completion bash-it.completion.bash - load_one plugins alias-completion.bash + load_one plugins alias-completion.plugin.bash + load_one aliases general.aliases.bash fi echo "" diff --git a/lib/preview.bash b/lib/preview.bash index 6e0d0357..306b475a 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -10,7 +10,8 @@ then THEMES="$BASH_IT/themes/*/*.theme.bash" for theme in $THEMES do - BASH_IT_THEME=$(basename -s '.theme.bash' $theme) + BASH_IT_THEME=${theme%.theme.bash} + BASH_IT_THEME=${BASH_IT_THEME##*/} echo " $BASH_IT_THEME" echo "" | bash --init-file $BASH_IT/bash_it.sh -i diff --git a/plugins/available/alias-completion.bash b/plugins/available/alias-completion.plugin.bash similarity index 100% rename from plugins/available/alias-completion.bash rename to plugins/available/alias-completion.plugin.bash diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index da244a8f..c094ac5b 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -196,3 +196,11 @@ function buf () local filetime=$(date +%Y%m%d_%H%M%S) cp -a "${filename}" "${filename}_${filetime}" } + +function del() { + about 'move files to hidden folder in tmp, that gets cleared on each reboot' + param 'file or folder to be deleted' + example 'del ./file.txt' + group 'base' + mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; +} diff --git a/plugins/available/boot2docker.bash b/plugins/available/boot2docker.plugin.bash similarity index 100% rename from plugins/available/boot2docker.bash rename to plugins/available/boot2docker.plugin.bash diff --git a/plugins/available/docker-machine.plugin.bash b/plugins/available/docker-machine.plugin.bash index 8c6c146f..fc2dc44d 100644 --- a/plugins/available/docker-machine.plugin.bash +++ b/plugins/available/docker-machine.plugin.bash @@ -1,11 +1,11 @@ cite about-plugin about-plugin 'Helpers to get Docker setup correctly for docker-machine' -# Note, this might need to be different if you use a machine other than 'dev', -# or its configured for a different IP +# Note, this might need to be different if you use a machine other than 'dev' if [[ `uname -s` == "Darwin" ]]; then - export DOCKER_HOST="tcp://192.168.99.100:2376" - export DOCKER_CERT_PATH="$HOME/.docker/machine/machines/dev" - export DOCKER_TLS_VERIFY=1 - export DOCKER_MACHINE_NAME="dev" + # check if dev machine is running + docker-machine ls | grep --quiet 'dev.*Running' + if [[ "$?" = "0" ]]; then + eval "$(docker-machine env dev)" + fi fi diff --git a/plugins/available/explain.plugin.bash b/plugins/available/explain.plugin.bash new file mode 100644 index 00000000..d57b78e2 --- /dev/null +++ b/plugins/available/explain.plugin.bash @@ -0,0 +1,24 @@ +cite about-plugin +about-plugin 'mankier.com explain function to explain other commands' + +explain () { + about 'explain any bash command via mankier.com manpage API' + param '1: Name of the command to explain' + example '$ explain # interactive mode. Type commands to explain in REPL' + example '$ explain 'cmd -o | ...' # one quoted command to explain it.' + group 'explain' + + if [ "$#" -eq 0 ]; then + while read -p "Command: " cmd; do + curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd" + done + echo "Bye!" + elif [ "$#" -eq 1 ]; then + curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1" + else + echo "Usage" + echo "explain interactive mode." + echo "explain 'cmd -o | ...' one quoted command to explain it." + fi +} + diff --git a/plugins/available/visual-studio-code.plugin.bash b/plugins/available/visual-studio-code.plugin.bash new file mode 100644 index 00000000..5bc20995 --- /dev/null +++ b/plugins/available/visual-studio-code.plugin.bash @@ -0,0 +1,12 @@ +cite about-plugin +about-plugin 'Defines the `code` executable for Visual Studio Code on OS X' + +# Based on https://code.visualstudio.com/Docs/editor/setup +if [[ `uname -s` == "Darwin" ]]; then + function code () { + about 'Starts Visual Studio Code in the provided directory' + group 'visual-studio-code' + + VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ; + } +fi diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 9fda847e..94e04209 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Path to the bash it configuration -export BASH_IT="$HOME/.bash_it" +export BASH_IT="{{BASH_IT}}" # Lock and Load a custom theme file # location /.bash_it/themes/