-
-
Save nemec/5b36fee11980e8f48c7d to your computer and use it in GitHub Desktop.
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 | |
# Place in ~/.local/share/nautilus/scripts and an option will be added to the | |
# Nautilus context menu to add the selected file(s) as favorites in the Gnome | |
# overlay. | |
IFS_BAK=$IFS | |
IFS=" | |
" | |
APP_FOLDER=~/.local/share/applications | |
mkdir -p ~/.cache/ | |
APPS=$(dconf read /org/gnome/shell/favorite-apps) | |
echo "dconf write /org/gnome/shell/favorite-apps \"$APPS\"" > ~/.cache/favs-script.backup | |
for line in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do | |
fname=$(basename $line) | |
if [[ "$line" = "" || "$line" = " " ]]; then | |
exit | |
else | |
dsk="$fname.desktop" | |
while [ -f "$APP_FOLDER/$dsk" ]; do | |
dsk="$fname.$RANDOM.desktop" | |
done | |
cat >"$APP_FOLDER/$dsk" <<EOL | |
[Desktop Entry] | |
Name=${fname} | |
Exec=xdg-open "${line}" | |
Type=Application | |
Terminal=false | |
EOL | |
chmod +x "$APP_FOLDER/$dsk" | |
new_apps="${APPS::-1}, '$dsk']" | |
dconf write /org/gnome/shell/favorite-apps "$new_apps" | |
fi | |
done | |
IFS=$IFS_BAK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment