Last active
September 17, 2020 13:29
-
-
Save dacap/a7bc51803032e2f84f181df3a473a094 to your computer and use it in GitHub Desktop.
open/close commands // or how to never write "xdg-" or "kill -9" again
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/bash | |
# open file/folder/url | |
if [[ "$(uname)" =~ "Darwin" ]] ; then | |
true # do nothing because macOS already have "open" command | |
elif [[ "$(uname)" == "Linux" ]] ; then | |
alias open=xdg-open | |
else | |
alias open=start | |
fi | |
# close processname | |
function close { | |
pids=$(ps -e | grep $1) | |
if [[ "$pids" != "" ]] ; then | |
while IFS= read -r line; do | |
pid=$(echo $line | tr -s ' ' | cut -d ' ' -f 2) | |
cmd=$(echo $line | tr -s ' ' | cut -d ' ' -f 5) | |
if [[ "$cmd" == "$1" ]] ; then | |
echo "Closing $cmd ($pid)" | |
kill -9 $pid | |
fi | |
done <<< "$pids" | |
else | |
echo Process $1 not found | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment