Skip to content

Instantly share code, notes, and snippets.

@anasayubi
Last active April 18, 2018 04:42
Show Gist options
  • Save anasayubi/0f0532265de628ed8480fef59bba8bf1 to your computer and use it in GitHub Desktop.
Save anasayubi/0f0532265de628ed8480fef59bba8bf1 to your computer and use it in GitHub Desktop.
Running GUI applications from the terminal without any hassle (with no weird GUI application output) and the terminal remains interactive for your usage!
#!/bin/bash
# Format:
# op.sh [PROGRAM] [FILE]
# op.sh -l -> lists the current screen sessions
# otherwise shows help
# ensure that screen is preinstalled on your system
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
if [[ $1 ]] && [[ $2 ]]
then
screen -d -m $1 $2
elif [[ $1 == -l ]]
then
screen -ls
elif [[ $1 == -h ]]
then
echo ${BOLD}Parameters allowed:${NORMAL}
echo op.sh \[FILE\] : open FILE with the default program
echo op.sh \[PROGRAM\] \[FILE\] : to open FILE with PROGRAM
echo op.sh -l : return all the detached sessions
echo op.sh -h : return help
echo Run any invalid command to output this help
elif [[ $1 ]]
then
FILE_MIME=$(xdg-mime query filetype $1)
APPLICATION=$(xdg-mime query default $FILE_MIME)
# now run application
gtk-launch $APPLICATION $1
else
echo ${BOLD}Incorrect usage of op.sh!
echo The following parameters are allowed:${NORMAL}
echo op.sh \[FILE\] : open FILE with the default program
echo op.sh \[PROGRAM\] \[FILE\] : to open FILE with PROGRAM
echo op.sh -l : return all the detached sessions
echo op.sh -h : return help
echo Run any invalid command to output this help
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment