Last active
April 25, 2016 06:48
-
-
Save imme-emosol/3580ee90ca579db14be9 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 .