Skip to content

Commit

Permalink
Press "d" to remove version in menu (#590)
Browse files Browse the repository at this point in the history
* Press "d" to remove version in menu

* changed "remove" to "delete"

* allow to delete active version and improved UX

* fixed menu message

* added comment to function
  • Loading branch information
thomasruiz authored and shadowspawn committed Oct 23, 2019
1 parent 0cbbefc commit 4e6ee60
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion bin/n
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ display_versions_with_selected() {
fi
done
echo
printf "Use up/down arrow keys to select a version, return key to install, q to quit"
printf "Use up/down arrow keys to select a version, return key to install, d to delete, q to quit"
}

#
Expand Down Expand Up @@ -448,6 +448,21 @@ menu_select_cache_versions() {
esac
fi
;;
"d")
clear
after_delete_selection="$(find_selection_after_delete "${selected}")"
[[ -n "${selected}" ]] && remove_versions "${selected}"

if [ "${after_delete_selection}" == "${selected}" ]; then
# If selection stays the same, it means that there is no version installed left.
clear
leave_fullscreen
echo "All versions have been deleted."
exit
fi

display_versions_with_selected "${after_delete_selection}"
;;
"k")
clear
selected="$(prev_version_installed "${selected}")"
Expand All @@ -473,6 +488,20 @@ menu_select_cache_versions() {
done
}

#
# Return either, and in this order, the next, the previous or the current version
#

find_selection_after_delete() {
selected="$1"
result=""
next="$(next_version_installed "${selected}")"
prev="$(prev_version_installed "${selected}")"
[[ "${next}" == ${selected} ]] && result="${prev}" || result="${next}"

echo "${result}"
}

#
# Move up a line and erase.
#
Expand Down

0 comments on commit 4e6ee60

Please sign in to comment.