Last active
April 25, 2016 06:48
-
-
Save imme-emosol/3580ee90ca579db14be9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/sh | |
#!/bin/sh -e | |
# The -e option for /bin/sh (dash) at the she-bang, | |
# makes this process immediately exit | |
# if some condition fails, see `man sh`. | |
evil_eval_check=$( set | grep '^shells_.*=' | cut -f 1 -d '=' ) | |
if test "x" != "x${evil_eval_check}" | |
then | |
echo 'Been injected with a posion.' | |
exit 0 | |
fi | |
i=0 | |
i=$(( i + 1 )) | |
eval "shells_${i}=byobu" | |
i=$(( i + 1 )) | |
eval "shells_${i}=bash" | |
i=$(( i + 1 )) | |
eval "shells_${i}=bash\ +o\ history" | |
eval "shells_${i}_desc=bash\ without\ history" | |
default_choice=2 | |
timeout_milliseconds=15 | |
j=0 | |
printf "\n"'Choose one of the following shells:'"\n" | |
while true | |
do | |
j=$(( j + 1 )) | |
if test "x" != "x"$( ( eval 'echo "${shells_'${j}'_desc+y}"' ) ) | |
then | |
desc=\$shells_${j}_desc | |
else | |
desc=\$shells_${j} | |
fi | |
eval "echo ' - '$j') '$desc'.'" | |
test "$j" -lt "$i" || break | |
done | |
echo ' - ''q'') ''exit without changes''(default).' | |
echo -n 'Press the identifier of your choice: ' | |
#chosen_shell=$( while ! head -c 1 ; do true ; done ) | |
# http://stackoverflow.com/a/32270158/165330 . | |
readchr () { | |
old_stty_cfg=$( stty -g ) | |
stty -echo raw min 0 time ${timeout_milliseconds} | |
printf '%s' $(dd bs=1 count=1 2>/dev/null) | |
stty $old_stty_cfg | |
} | |
chosen_shell=$( readchr ) | |
if [ "x" = "x$chosen_shell" ] | |
then | |
#echo 'setting default choice('$chosen_shell').' | |
chosen_shell=$default_choice | |
fi | |
if test "1" != "$chosen_shell" && test "2" != "$chosen_shell" && test "3" != "$chosen_shell" | |
then | |
exit 1 | |
fi | |
eval "shell_choice=\$shells_${chosen_shell}" | |
if command -v wmctrl >/dev/null 2>&1 && test "byobu" = "$shell_choice" | |
then | |
$( wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz ) | |
fi | |
if test "bash" = "$shell_choice" | |
then | |
$( wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz ) | |
clear | |
fi | |
exec $shell_choice |
thnX :)
de output zonder -vx is wel een stukkie fraaier ..
En ik ben ook benieuwd naar de output vanuit een andere shell omgeving dan bash .
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
stefanjonker at MexBook in ~/Desktop/script
$ bash -vx ./shellchooser.sh
!/bin/sh -e
The -e option for /bin/sh at the she-bang,
makes this process immediately exit
if some condition fails, see
man sh
.evil_eval_check=$( set | grep '^shells_.=' | cut -f 1 -d '=' )
set | grep '^shells.=' | cut -f 1 -d '='
++ set
++ grep '^shells.*='
++ cut -f 1 -d =
if test "x" != "x${evil_eval_check}"
then
echo 'Been injected with a posion.'
exit 0
fi
i=0
i=$(( i + 1 ))
eval "shells_${i}=byobu"
shells_1=byobu
++ shells_1=byobu
i=$(( i + 1 ))
eval "shells_${i}=bash"
shells_2=bash
++ shells_2=bash
i=$(( i + 1 ))
eval "shells_${i}=bash\ +o\ history"
shells_3=bash\ +o\ history
++ shells_3='bash +o history'
eval "shells_${i}_desc=bash\ without\ history"
shells_3_desc=bash\ without\ history
++ shells_3_desc='bash without history'
default_choice=2
timeout_milliseconds=15
j=0
printf "\n"'Choose one of the following shells:'"\n"
Choose one of the following shells:
while true
do
j=$(( j + 1 ))
if test "x" != "x"$( ( eval 'echo "${shells_'${j}'desc+y}"' ) )
then
desc=$shells${j}desc
else
desc=$shells${j}
fi
eval "echo ' - '$j') '$desc'.'"
test "$j" -lt "$i" || break
done
( eval 'echo "${shells_'${j}'_desc+y}"' )
++ eval 'echo "${shells_1_desc+y}"'
echo "${shells_1_desc+y}"
+++ echo ''
echo ' - '1') '$shells_1'.'
++ echo ' - 1) byobu.'
( eval 'echo "${shells_'${j}'_desc+y}"' )
++ eval 'echo "${shells_2_desc+y}"'
echo "${shells_2_desc+y}"
+++ echo ''
echo ' - '2') '$shells_2'.'
++ echo ' - 2) bash.'
( eval 'echo "${shells_'${j}'_desc+y}"' )
++ eval 'echo "${shells_3_desc+y}"'
echo "${shells_3_desc+y}"
+++ echo y
echo ' - '3') '$shells_3_desc'.'
++ echo ' - 3) bash' without history.
echo ' - ''q'') ''exit without changes''(default).'
echo -n 'Press the identifier of your choice: '
Press the identifier of your choice: #chosen_shell=$( while ! head -c 1 ; do true ; done )
http://stackoverflow.com/a/32270158/165330 .
readchr () {old_stty_cfg=$( stty -g )
stty -echo raw min 0 time ${timeout_milliseconds}
printf '%s' $(dd bs=1 count=1 2>/dev/null)
stty $old_stty_cfg
}
chosen_shell=$( readchr )
readchr
++ readchr
stty -g
+++ stty -g
++ old_stty_cfg=gfmt1:cflag=4b00:iflag=6b02:lflag=200005cb:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=9600:ospeed=9600
++ stty -echo raw min 0 time 15
dd bs=1 count=1 2>/dev/null
+++ dd bs=1 count=1
++ printf %s
++ stty gfmt1:cflag=4b00:iflag=6b02:lflag=200005cb:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=9600:ospeed=9600
+ chosen_shell=
if [ "x" = "x$chosen_shell" ]
then
#echo 'setting default choice('$chosen_shell').'
chosen_shell=$default_choice
fi
if test "1" != "$chosen_shell" && test "2" != "$chosen_shell" && test "3" != "$chosen_shell"
then
exit 1
fi
eval "shell_choice=$shells_${chosen_shell}"
shell_choice=$shells_2
++ shell_choice=bash
if command -v wmctrl >/dev/null 2>&1 && test "byobu" = "$shell_choice"
then
$( wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz )
fi
if test "bash" = "$shell_choice"
then
$( wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz )
clear
fi
wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
++ wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
exec $shell_choice
bash-3.2$