From 967d4b7cd4fc0a55bf33a0029f5e4fa988419348 Mon Sep 17 00:00:00 2001 From: Andres Gongora Date: Sat, 18 Apr 2020 12:00:15 +0200 Subject: [PATCH] Fix setup script Signed-off-by: Andres Gongora --- README.md | 22 ++++++++++++++++------ config/synth-shell-prompt.config | 2 +- setup.sh | 15 +++++++++++---- synth-shell-prompt/synth-shell-prompt.sh | 18 +++++++++++------- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 653e7a1..88bf1fd 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,14 @@ You may install `synth-shell-prompt` from AUR: https://aur.archlinux.org/packages/synth-shell-prompt-git/ +Once installed, test it with: +``` +. /usr/bin/synth-shell-greeter +``` +And if you like it, add it permanently to your terminal with: +``` +echo ". /usr/bin/synth-shell-greeter" >> ~/.bashrc +``` @@ -34,15 +42,17 @@ git clone --recursive https://github.com/andresgongora/synth-shell-greeter.git synth-shell-greeter/setup.sh ``` -You can then test your script by running it from wherever you installed it. -Usually this is to your user's `.config` folder, so you should run: +You can then test your script by sourcing it from wherever you installed it. +Usually this is to your user's `.config` folder, so you should run the following +command. Notice the `.`, this is meant to source the script to your +terminal session (i.e. include it into your session). ``` -~/.config/synth-shell/synth-shell-greeter.sh +. ~/.config/synth-shell/synth-shell-greeter.sh ``` -If you want it to appear everytime you open a new terminal, run +If you want it to appear everytime you open a new terminal, run either ``` -echo "~/.config/synth-shell/synth-shell-greeter.sh" >> ~/.bashrc +echo ". ~/.config/synth-shell/synth-shell-greeter.sh" >> ~/.bashrc ``` @@ -79,7 +89,7 @@ to indicate the state of the repository (can be changed in the config file): | Local-Upstream | Local branch has no changes | Local branch is dirty | |:--------------------------------:|:---------------------------:|:---------------------:| -| Up to date | | ! | +| Up to date | | □ | | Ahead (you have to push) | ▲ | △ | | Behind (you have to pull) | ▼ | ▽ | | Diverged (you have to pull-push) | ● | ○ | diff --git a/config/synth-shell-prompt.config b/config/synth-shell-prompt.config index e08e175..d805b8d 100644 --- a/config/synth-shell-prompt.config +++ b/config/synth-shell-prompt.config @@ -46,7 +46,7 @@ texteffect_input="bold" ## BEHAVIOR ##============================================================================== -local separator_char='\uE0B0' # Separation character, '\uE0B0'=triangle +separator_char='\uE0B0' # Separation character, '\uE0B0'=triangle enable_vertical_padding=true # Add extra new line over prompt diff --git a/setup.sh b/setup.sh index e4f800a..1e04d59 100755 --- a/setup.sh +++ b/setup.sh @@ -27,20 +27,27 @@ ##============================================================================== -## -include(){ { [ -z "$_IR" ]&&_IR="$PWD"&&cd "$(dirname "$PWD/$0")"&&include "$1"&&cd "$_IR"&&unset _IR;}||{ local d=$PWD&&cd "$(dirname "$PWD/$1")"&&. "$(basename "$1")"&&cd "$d";}||{ echo "Include failed $PWD->$1"&&exit 1;};} +## EXTERNAL DEPENDENCIES +##============================================================================== +[ "$(type -t include)" != 'function' ]&&{ include(){ { [ -z "$_IR" ]&&_IR="$PWD"&&cd $(dirname "${BASH_SOURCE[0]}")&&include "$1"&&cd "$_IR"&&unset _IR;}||{ local d=$PWD&&cd "$(dirname "$PWD/$1")"&&. "$(basename "$1")"&&cd "$d";}||{ echo "Include failed $PWD->$1"&&exit 1;};};} include 'bash-tools/bash-tools/user_io.sh' include 'bash-tools/bash-tools/hook_script.sh' include 'bash-tools/bash-tools/assemble_script.sh' + + + + +##============================================================================== +## SETUP +##============================================================================== + ## SWITCH BETWEEN AUTOMATIC AND USER INSTALLATION if [ "$#" -eq 0 ]; then OUTPUT_SCRIPT="$HOME/.config/synth-shell/synth-shell-prompt.sh" OUTPUT_CONFIG_DIR="$HOME/.config/synth-shell" - cp "$OUTPUT_CONFIG_DIR/synth-shell-prompt.config" \ - "$OUTPUT_CONFIG_DIR/synth-shell-prompt.config.backup" printInfo "Installing script as $OUTPUT_SCRIPT" USER_CHOICE=$(promptUser "Add hook your .bashrc file or equivalent?\n\tRequired for autostart on new terminals" "[Y]/[n]?" "yYnN" "y") case "$USER_CHOICE" in diff --git a/synth-shell-prompt/synth-shell-prompt.sh b/synth-shell-prompt/synth-shell-prompt.sh index eac188a..620376f 100755 --- a/synth-shell-prompt/synth-shell-prompt.sh +++ b/synth-shell-prompt/synth-shell-prompt.sh @@ -53,9 +53,6 @@ include '../config/synth-shell-prompt.config' synth_shell_prompt() { - - - ##============================================================================== ## FUNCTIONS ##============================================================================== @@ -229,8 +226,9 @@ prompt_command_hook() -##------------------------------------------------------------------------------ -## +##============================================================================== +## MAIN +##============================================================================== ## LOAD USER CONFIGURATION local user_config_file="$HOME/.config/synth-shell/synth-shell-prompt.config" @@ -322,12 +320,18 @@ prompt_command_hook() } -## CALL SCRIPT +## CALL SCRIPT FUNCTION +## CHECK IF SCRIPT IS _NOT_ BEING SOURCED ## CHECK IF COLOR SUPPORTED ## - Check if compliant with Ecma-48 (ISO/IEC-6429) ## - Call script ## - Unset script -if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then +if [ "${BASH_SOURCE[0]}" == "${0}" ]; then + echo -e "Do not run this script, it will do nothing.\nPlease source it instead by running:\n" + echo -e "\t. ${BASH_SOURCE[0]}\n" + +elif [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then synth_shell_prompt unset synth_shell_prompt + fi