Created
January 10, 2011 15:21
-
-
Save Ruxton/772887 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# __selector: "prompt", "returnvar", "current_selected", "selection_list" | |
# | |
# __selector "Select a volume", "selected_volume", "", `ls -la /Volumes/` | |
# cd $selected_volume | |
# | |
function __selector() { | |
local selections selPrompt selCurrent selListCommand selSize choose | |
selPrompt=$1 | |
selReturn=$2 | |
selCurrent=$3 | |
selList=$4 | |
prompt=$selPrompt | |
let count=0 | |
for sel in $selList; do | |
let count++ | |
selections[$count-1]=$sel | |
done | |
if [[ $count > 0 ]]; then | |
choose=0 | |
selSize=${#selections[@]} | |
while [ $choose -eq 0 ]; do | |
let count=0 | |
for sel in $selList; do | |
let count++ | |
echo "$count) $sel" | |
done | |
echo | |
read -p "${prompt}, followed by [ENTER]:" choose | |
if [[ $choose != ${choose//[^0-9]/} ]] || [ ! $choose -le $selSize ] | |
then | |
echo | |
echo "Please choose one of the listed numbers." | |
echo | |
let choose=0 | |
fi | |
done | |
let choose-- | |
export ${selReturn}=${selections[$choose]} | |
else | |
return 0 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment