Skip to content

Commit d29a024

Browse files
committed
Added warning when no 'swuser' action provided & when attempting to switch to self.
1 parent 03619c3 commit d29a024

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

swuser

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ function usage() {
2727
printf " -u switch to a different user by user id\n"
2828
}
2929

30+
function check_id() {
31+
if (( $1 == $2 )); then
32+
printf "Sorry, you can't switch to yourself.\n"
33+
exit 1;
34+
fi
35+
}
36+
3037
# exit with an error if being run from screen
3138
if [ "$STY" != "" ]; then
3239
printf "Sorry, swuser doesn't work from within screen. I know, I hate it too!\n"
@@ -48,14 +55,20 @@ if [ $# -gt 0 ]; then
4855
# handle switching to another user by name
4956
elif [ "$1" = "-n" ]; then
5057
shift
58+
new_id=$(id -u "$1")
59+
check_id $id $new_id
5160
"$cgsession" -switchToUserID $(id -u "$1")
5261
shift
5362
# handle switch to another user by id
5463
elif [ "$1" = "-u" ]; then
5564
shift
65+
check_id $id $1
5666
"$cgsession" -switchToUserID $1
5767
shift
5868
fi
5969
done
70+
else
71+
printf "No switch user action specified.\n\n"
72+
usage
6073
fi
6174

0 commit comments

Comments
 (0)