diff --git a/bash-completion/detoul b/bash-completion/detoul index 75794f7..41fb5ec 100644 --- a/bash-completion/detoul +++ b/bash-completion/detoul @@ -4,11 +4,11 @@ _detoul() { local line="${COMP_LINE}" if (echo "$line" | grep -q "^[[:graph:]]\+\s\+edit\+\s\+[[:graph:]]\+\s"); then - _script_commands=$(detoul options "$(echo "$line" | sed -e 's/^[[:graph:]]\+\s\+\([[:graph:]]\+\).*/\1/')") + _script_commands=$(detoul options "$(echo "$line" | sed -E 's/^[[:graph:]]+\s+([[:graph:]]+).*/\1/')") elif (echo "$line" | grep -q "^[[:graph:]]\+\s\+[[:graph:]]\+\s\+[[:graph:]]\+\s\+[[:graph:]]\+\s"); then - _script_commands=$(detoul options "$(echo "$line" | sed -e 's/^[[:graph:]]\+\s\+\([[:graph:]]\+\).*/\1/')") + _script_commands=$(detoul options "$(echo "$line" | sed -E 's/^[[:graph:]]+\s+([[:graph:]]+).*/\1/')") elif (echo "$line" | grep -q "^[[:graph:]]\+\s\+[[:graph:]]\+\s\+[[:graph:]]\+\s"); then - _script_commands=$((git tag; git branch -a | grep -v "\->" | sed -e 's/remotes\/[[:alnum:]]\+\///g' | cut -c3- | sort | uniq | grep -v "^detoul-spec$") | xargs) + _script_commands=$((git tag; git branch -a | grep -v "\->" | sed -E 's/remotes\/[[:alnum:]]+\///g' | cut -c3- | sort | uniq | grep -v "^detoul-spec$") | xargs) elif [ "$(echo "$line" | wc -w)" == "1" ]; then _script_commands=$(detoul commands) elif ([ "$(echo "$line" | wc -w)" == "2" ] && ! (echo "$line" | grep -q "\s$")); then diff --git a/detoul b/detoul index 6142742..534b8fd 100755 --- a/detoul +++ b/detoul @@ -1,5 +1,9 @@ #!/bin/bash +COLOR_RED="$(tput setaf 1)" +COLOR_GREEN="$(tput setaf 2)" +COLOR_CLR="$(tput sgr0)" + if [ -t 1 -o "$DETOUL_COLOR_ALWAYS" == "1" ]; then remove_colors="cat" else @@ -108,7 +112,7 @@ save-spec() { stash ( git checkout detoul-spec && - (cat "$DETOUL_TMP/spec" | head -n -1 | grep -v "^$" > "$target" || [ 1 -eq 1 ]) && + (cat "$DETOUL_TMP/spec" | awk -v n=1 'NR>n{print line[NR%n]};{line[NR%n]=$0}' | grep -v "^$" > "$target" || [ 1 -eq 1 ]) && cat "$DETOUL_TMP/spec" | tail -n 1 | tr -d '\n' >> "$target" && git add "$target" && git commit -m "$1" $commit_opts @@ -117,8 +121,6 @@ save-spec() { cd - >/dev/null } -(( - if [ $# -lt 1 ]; then help fi @@ -286,7 +288,7 @@ save-spec() { case "$1" in test) git branch -D "$DETOUL_BRANCH" >/dev/null 2>&1 - echo -e "\e[32mIntegration branch succesfully created.\e[0m" + echo -e "${COLOR_GREEN}Integration branch succesfully created.${COLOR_CLR}" ;; make) git checkout "$DETOUL_BRANCH" >/dev/null 2>&1 @@ -298,7 +300,7 @@ save-spec() { ;; *) git branch -D "$DETOUL_BRANCH" >/dev/null 2>&1 - echo -e "\e[31mUnknown operation '$1'.\e[0m" >&2 + echo -e "${COLOR_RED}Unknown operation '$1'.${COLOR_CLR}" >&2 fail esac quit @@ -309,7 +311,7 @@ save-spec() { stash-pop fi git branch -D "$DETOUL_BRANCH" >/dev/null 2>&1 - echo -e "\e[31mFailure.\e[0m" >&2 + echo -e "${COLOR_RED}Failure.${COLOR_CLR}" >&2 fail fi diff --git a/detoul-base b/detoul-base index 6627ec3..5a90fab 100755 --- a/detoul-base +++ b/detoul-base @@ -1,5 +1,12 @@ #!/bin/bash +COLOR_RED="$(tput setaf 1)" +COLOR_GREEN="$(tput setaf 2)" +COLOR_YELLOW="$(tput setaf 3)" +COLOR_MAGENTA="$(tput setaf 5)" +COLOR_CYAN="$(tput setaf 6)" +COLOR_CLR="$(tput sgr0)" + exit_code="0" first_command="1" @@ -21,11 +28,11 @@ make-detoul-dependency() { export DETOUL_COLOR_ALWAYS="1" if ( detoul cat "$1" >/dev/null 2>&1 ); then if ( git ls-tree detoul-spec | grep -q "\s$1$" ); then - echo -e "Making spec '\e[92m$1\e[0m...'" && + echo -e "Making spec '${COLOR_GREEN}$1${COLOR_CLR}...'" && detoul make "$1" && echo "0" >"$exit_code_file" else - echo -e "\e[93mWarning: there is an archived detoul spec called '\e[92m$1\e[93m'.\e[0m" + echo -e "${COLOR_YELLOW}Warning: there is an archived detoul spec called '${COLOR_GREEN}$1${COLOR_YELLOW}'.${COLOR_CLR}" echo "0" >"$exit_code_file" fi else @@ -38,7 +45,7 @@ make-detoul-dependency() { } autocomplete() { - branch_name="$((git branch -a | cut -c3- ; git tag) | sed -e 's/remotes\/[[:alnum:]]\+\///g' | grep "^$1" | head -n 1)" + branch_name="$((git branch -a | cut -c3- ; git tag) | sed -E 's/remotes\/[[:alnum:]]+\///g' | grep "^$1" | head -n 1)" if [ "$branch_name" == "" ]; then echo "$1" else @@ -47,7 +54,7 @@ autocomplete() { } validate-branch-name() { - (git branch -a | cut -c3- ; git tag) | sed -e 's/remotes\/[[:alnum:]]\+\///g' | grep -q "^$1$" + (git branch -a | cut -c3- ; git tag) | sed -E 's/remotes\/[[:alnum:]]+\///g' | grep -q "^$1$" } validate-ref-name() { @@ -56,12 +63,12 @@ validate-ref-name() { checkout() { if [ "$first_command" == "1" ]; then - color="\e[0m" + color="${COLOR_CLR}" first_command=0 else - color="\e[91m" + color="${COLOR_RED}" fi - echo -e "${color}Checking out\e[0m '\e[92m$branch\e[0m'..." + echo -e "${color}Checking out${COLOR_CLR} '${COLOR_GREEN}$branch${COLOR_CLR}'..." if ( (git branch ; git tag) | grep -q "\b${branch}$" ); then checkout_branch="$branch" else @@ -130,9 +137,9 @@ take() { cached_commit_key="$(detoul-cache hash take $@)" if [ "$3" == "" ]; then if [ "$1" == "" ]; then - echo -e "Taking '\e[92m$branch\e[0m'..." + echo -e "Taking '${COLOR_GREEN}$branch${COLOR_CLR}'..." else - echo -e "Taking '\e[92m$branch\e[0m' (\e[96m$(echo "$1" | cut -d'-' -f1)\e[0m)..." + echo -e "Taking '${COLOR_GREEN}$branch${COLOR_CLR}' (${COLOR_CYAN}$(echo "$1" | cut -d'-' -f1)${COLOR_CLR})..." fi cached_commit="$(detoul-cache read "$cached_commit_key")" if [ $? -ne 0 ] || ! (git reset --hard "$cached_commit" >/dev/null 2>&1); then @@ -141,7 +148,7 @@ take() { return fi elif [ "$3" == "refresh" ]; then - echo -e "\e[93mAttempting to refresh rerere cache...\e[0m" >&2 + echo -e "${COLOR_YELLOW}Attempting to refresh rerere cache...${COLOR_CLR}" >&2 fi source_branch="$(git show-ref "$branch" | cut -d' ' -f1 | head -n 1)" if [ "${1/squash}" != "$1" ]; then @@ -202,7 +209,7 @@ pick() { branch="${command[1]}" checkout else - echo -e "Picking '\e[92m${command[1]}\e[0m'..." + echo -e "Picking '${COLOR_GREEN}${command[1]}${COLOR_CLR}'..." ( git cherry-pick "${command[1]}" ) >/dev/null 2>&1 || fail @@ -219,7 +226,7 @@ while read -r line; do export branch="$(autocomplete "${command[1]//\*/.*}")" (make-detoul-dependency "$branch") || fail if ! validate-ref-name "$branch" ; then - echo -e "\e[31mReference not found: '$branch'.\e[0m" >&2 + echo -e "${COLOR_RED}Reference not found: '$branch'.${COLOR_CLR}" >&2 fail fi case "${command[0]}" in @@ -230,21 +237,21 @@ while read -r line; do take ;; take-merge) - take merge-squash "$(echo "$line" | sed -e 's/^take-merge\s\+[[:graph:]]\+\s*//')" + take merge-squash "$(echo "$line" | sed -E 's/^take-merge\s+[[:graph:]]+\s*//')" ;; take-squash) - take squash "$(echo "$line" | sed -e 's/^take-squash\s\+[[:graph:]]\+\s*//')" + take squash "$(echo "$line" | sed -E 's/^take-squash\s+[[:graph:]]+\s*//')" ;; pick) pick ;; exec) - echo -e "\e[91mExecuting\e[0m '\e[92m${line/exec /}\e[0m'..." + echo -e "${COLOR_RED}Executing${COLOR_CLR} '${COLOR_GREEN}${line/exec /}${COLOR_CLR}'..." cd "$GIT_WD" bash -c "${line/exec /}" || fail ;; *) - echo -e "\e[31mUnknown directive '${command[0]}'.\e[0m" >&2 + echo -e "${COLOR_RED}Unknown directive '${command[0]}'.${COLOR_CLR}" >&2 fail ;; esac diff --git a/load-detoul-spec b/load-detoul-spec index 9589bdb..50b60ec 100755 --- a/load-detoul-spec +++ b/load-detoul-spec @@ -1,5 +1,8 @@ #!/bin/bash +COLOR_RED="$(tput setaf 1)" +COLOR_CLR="$(tput sgr0)" + spec="$DETOUL_TMP/spec" rm -f "$spec" @@ -15,7 +18,7 @@ rm -f "$spec" spec_hash="$(git ls-tree detoul-spec -- .archive/ | grep "\s.archive/$DETOUL_BRANCH$" | xargs echo | cut -d' ' -f3)" fi if [ "$spec_hash" == "" ]; then - echo -e "\e[31mBranch specification file not found.\e[0m" + echo -e "${COLOR_RED}Branch specification file not found.${COLOR_CLR}" exit 1 fi fi