Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bash-completion/detoul
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions detoul
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ]) &&

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add awk as a dependency. Find an alternative solution.

Before it comes up: not python, node, ruby, php, or perl either. We have perl in colorize, but colorize isn't a core file (it can be skipped).

@yossi-dy yossi-dy Feb 25, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for using awk as an alternative method was OSX's head command doesn't support negative values (so you can't exclude the last line, like you intended here).
Would you consider coreutils (https://www.gnu.org/software/coreutils/manual/html_node/head-invocation.html) as a polyfil?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the problem, please find a solution that doesn't add awk (or another language) as a dependency.

If you can't find a different solution for Mac, you maybe can create create a new executable file here called skip_last_line or something that checks the OS, and if it's GNU head (head --version | head -n1 | grep -q GNU) uses head and otherwise uses awk.

cat "$DETOUL_TMP/spec" | tail -n 1 | tr -d '\n' >> "$target" &&
git add "$target" &&
git commit -m "$1" $commit_opts
Expand All @@ -117,8 +121,6 @@ save-spec() {
cd - >/dev/null
}

((

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's what you meant to do.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep :-) found it out last night. Will put those back in place.


if [ $# -lt 1 ]; then
help
fi
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
39 changes: 23 additions & 16 deletions detoul-base
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion load-detoul-spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

COLOR_RED="$(tput setaf 1)"
COLOR_CLR="$(tput sgr0)"

spec="$DETOUL_TMP/spec"
rm -f "$spec"

Expand All @@ -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
Expand Down