Skip to content

Instantly share code, notes, and snippets.

@MrMohebi
Created July 30, 2022 04:51
Show Gist options
  • Save MrMohebi/f04dde07ac7d244f03e32827df5b5ab1 to your computer and use it in GitHub Desktop.
Save MrMohebi/f04dde07ac7d244f03e32827df5b5ab1 to your computer and use it in GitHub Desktop.
create desktop icon and symbol link for executable file
#!/bin/bash
usage() {
__usage="
Usage: $(basename $0) [OPTIONS]
Options:
-p, executable path <string> [required] Absolute path to executable file
-i, icon path <string> [required] Absolute path ti icon file
-c, command <string> [required] Command shortcut name for executable file
-h, help help
"
echo "$__usage"
exit 1;
}
while getopts h:c:i:p: flag; do
case "${flag}" in
i) icon=${OPTARG};;
c) command=${OPTARG};;
p) path=${OPTARG};;
h) usage;;
*) usage
esac
done
if [ "$command" == '' ] || [ "$path" == '' ] || [ "$icon" == '' ]; then
usage;
exit 0;
fi
sudo ln -s "$path" /usr/bin/"$command" || echo "link exist"
sudo tee /usr/share/applications/"$command".desktop > /dev/null <<EOT
[Desktop Entry]
Version=1.0
Name=$command
Comment=$command
Exec=$command
Icon=$icon
Terminal=false
Type=Application
Categories=Utility;Development;
EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment