learn-it / scripting

Learn to do scripting with Bash, Perl, Python and others
1 stars 0 forks source link

Midnight Commander subshell trolling guard #1

Open midenok opened 10 years ago

midenok commented 10 years ago

To avoid horrible subshell trolling (when you forget and run MC under MC), you can do following dirty hack. Put this into your .bashrc:

check_mc()
{
    if [ -n "$MC_SID" ]
    then
        echo You are under mc!
    else
        "$@"
    fi
}

mc() { check_mc /usr/bin/mc "$@"; }
sudo()
{
    if [ -z "$1" ]
    then
        check_mc /usr/bin/sudo
    else
        /usr/bin/sudo "$@"
    fi
}
ssh() { check_mc /usr/bin/ssh "$@"; }
midenok commented 10 years ago

Better solution would be suspend MC and run command in parent shell. Anyone's try to make script for this is welcome!