-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_desktop.sh
More file actions
56 lines (44 loc) · 2.17 KB
/
create_desktop.sh
File metadata and controls
56 lines (44 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# By Diego Cardenas "The Samedog" under GNU GENERAL PUBLIC LICENSE Version 2, June 1991
# (www.gnu.org/licenses/old-licenses/gpl-2.0.html) e-mail: the.samedog[]gmail.com.
# https://github.com/samedog
##########################################################################################
#
# THIS SCRIPT IS A SET OF HORRIBLE HACKS, IT MIGHT WORK, MIGHT OPEN A VORTEX
# AND SEND YOU TO A COMPLETELY DIFFERENT UNIVERSE, OR MIGHT DO SHIT, WHO KNOWS?.
#
##########################################################################################
# Version: 1.0
################################## Code begins here #######################################
#icon, name and terminal (true/false) are options
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <file_path> [icon_path] [name] [terminal]"
exit 1
fi
FILE_PATH="$(realpath "$1")"
ICON_PATH="$(realpath "${2:-}")"
CUSTOM_NAME="${3:-$(basename "$FILE_PATH")}"
TERMINAL="${4:-false}"
DESKTOP_FILE="/usr/share/applications/$CUSTOM_NAME.desktop"
if [[ "$FILE_PATH" == *.sh ]]; then
sudo chmod +x "$FILE_PATH"
echo "[Desktop Entry]" | sudo tee "$DESKTOP_FILE" > /dev/null
echo "Version=1.0" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Type=Application" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Name=$CUSTOM_NAME" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Exec=bash \"$FILE_PATH\"" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Terminal=True" | sudo tee -a "$DESKTOP_FILE" > /dev/null #terminal always true for terminal apps, duh
else
# Create the .desktop file for a non-script file
echo "[Desktop Entry]" | sudo tee "$DESKTOP_FILE" > /dev/null
echo "Version=1.0" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Type=Application" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Name=$CUSTOM_NAME" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Exec=xdg-open \"$FILE_PATH\"" | sudo tee -a "$DESKTOP_FILE" > /dev/null
echo "Terminal=false" | sudo tee -a "$DESKTOP_FILE" > /dev/null
fi
if [ -n "$ICON_PATH" ]; then
echo "Icon=$ICON_PATH" | sudo tee -a "$DESKTOP_FILE" > /dev/null
fi
sudo chmod +x "$DESKTOP_FILE"
echo "Created system-wide desktop shortcut: $DESKTOP_FILE"