-
Notifications
You must be signed in to change notification settings - Fork 16
umpf: highlight default choice in lists #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,6 +421,25 @@ nice_branch() { | |
read -r -a replies < <(sed -r -n 's,^(remotes/([^/]*)/|heads/)?(.*),\3 \2,p' <<< "${1}") | ||
} | ||
|
||
add_choice() { | ||
choices+=("$1") | ||
choice_descs+=("$2") | ||
} | ||
|
||
print_choices() { | ||
local i default choice | ||
default="$1" | ||
for i in "${!choices[@]}"; do | ||
if [ "${default}" = "${choices[${i}]}" ]; then | ||
echo -en '\e[1m' | ||
echo "${choices[${i}]}) ${choice_descs[${i}]}" | ||
echo -en '\e[0m' | ||
else | ||
echo "${choices[${i}]}) ${choice_descs[${i}]}" | ||
fi; | ||
done; | ||
} | ||
|
||
read_interactive() { | ||
local prompt="${1}" def="${2}" | ||
if ${DEFAULT} && [ -n "${def}" ]; then | ||
|
@@ -456,14 +475,17 @@ find_branch_rev() { | |
info "Branch not found for '${remote}'. Choose alternative branch:" | ||
fi | ||
local i=0 def=0 choice | ||
# shellcheck disable=SC2034 | ||
local -a choices choices_descs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you can declare local variable in the middle of a function inside a loop, they will not actually go out of scope at the end of the loop body. You need to explicitly initialize the variables, e.g. |
||
for branch in "${branches[@]}"; do | ||
nice_branch "${branch}" | ||
echo "${i}) ${replies[1]:+${replies[1]}/}${replies[0]}" | ||
add_choice "${i}" "${replies[1]:+${replies[1]}/}${replies[0]}" | ||
if [ "${GIT_FALLBACK_REMOTE}" == "${replies[1]}/" ]; then | ||
def="${i}" | ||
fi | ||
i=$((i+1)) | ||
done | ||
print_choices "${def}" | ||
read_interactive "branch number" "${def}" | ||
nice_branch "${branches[${choice}]}" | ||
remote="${replies[1]:-refs/heads}/" | ||
|
@@ -1706,15 +1728,18 @@ apply_to_topic() { | |
|
||
while [ -z "${topic}" ]; do | ||
local i=0 choice default | ||
# shellcheck disable=SC2034 | ||
local -a choices choice_descs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
for branch in "${branch_names[@]}"; do | ||
echo "${i}) ${branch}" | ||
add_choice "${i}" "${branch}" | ||
if git log --pretty="format:%s" "${base}..${branches[${i}]}" | grep -q "^${match}$"; then | ||
default="${i}" | ||
fi | ||
i=$((i+1)) | ||
done | ||
echo "s) show patch" | ||
echo "x) skip patch" | ||
add_choice "s" "show patch" | ||
add_choice "x" "skip patch" | ||
print_choices "${default}" | ||
read_interactive "Branch" "${default}" | ||
case "${choice}" in | ||
s) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
choice
is unused.