-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathappimage-desktop-entry.sh
executable file
·66 lines (53 loc) · 1.38 KB
/
appimage-desktop-entry.sh
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
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
set -e
set -o pipefail
APPIMAGE_PATH=$1
if [ -z "$APPIMAGE_PATH" ]; then
echo "Missing argument: appimage"
exit 1
fi
if [ ! -f "$APPIMAGE_PATH" ]; then
echo "File not found: $APPIMAGE_PATH"
exit 1
fi
TEMP_SQUASHFS_PATH=$(mktemp -d)
APPIMAGE_FULLPATH=$(readlink -e "$APPIMAGE_PATH")
APPIMAGE_FILENAME=$(basename "$APPIMAGE_PATH")
APP_NAME="${APPIMAGE_FILENAME%.*}"
DESKTOP_ENTRY_PATH="${HOME}/.local/share/applications/$APP_NAME.desktop"
ICON_FOLDER="${HOME}/.local/share/icons"
mkdir -p "${ICON_FOLDER}"
if [ "$2" == "--remove" ]; then
rm -f "$DESKTOP_ENTRY_PATH"
find "${ICON_FOLDER}" -maxdepth 1 -type f -name "$APP_NAME.*" -delete
echo "Removed"
exit 0
fi
pushd $TEMP_SQUASHFS_PATH
"$APPIMAGE_FULLPATH" --appimage-extract > /dev/null
cd squashfs-root/
echo "Choose icon: "
mapfile -t FILENAMES < <(find -L . -maxdepth 1 -type f \( -iname '*.png' -o -iname '*.svg' \))
i=1
for filename in "${FILENAMES[@]}"
do
printf " %d) %s\n" "$i" "$filename"
i=$((i + 1))
done
read -r SELECTED_INDEX
ICON_SRC=${FILENAMES[$((SELECTED_INDEX - 1))]}
ICON_EXT="${ICON_SRC##*.}"
ICON_DST="${ICON_FOLDER}/$APP_NAME.$ICON_EXT"
cp "$ICON_SRC" "$ICON_DST"
cat <<EOT > "$DESKTOP_ENTRY_PATH"
[Desktop Entry]
Name=$APP_NAME
StartupWMClass=$APP_NAME
Exec="$APPIMAGE_FULLPATH"
Icon=$ICON_DST
Type=Application
Terminal=false
EOT
popd
rm -rf $TEMP_SQUASHFS_PATH
echo "Created"