diff --git a/create-link-here@DopeyDave/CHANGELOG.md b/create-link-here@DopeyDave/CHANGELOG.md new file mode 100644 index 00000000..bd7d37cc --- /dev/null +++ b/create-link-here@DopeyDave/CHANGELOG.md @@ -0,0 +1,3 @@ +### 1.0 + +* Initial Release \ No newline at end of file diff --git a/create-link-here@DopeyDave/README.md b/create-link-here@DopeyDave/README.md new file mode 100644 index 00000000..abd146cc --- /dev/null +++ b/create-link-here@DopeyDave/README.md @@ -0,0 +1,21 @@ +Create a Link Here +======================== + +Description +----------- + +This Action adds the ability to create a link "here" (in the same folder) for a file or folder. The link is created using the .desktop file type, which allows for proper path tracking and display on the Desktop (if the shortcut happens to be moved there). + +The behavior is similar to the Windows "create a shortcut" / "send to desktop" functionality. + +**Difference from Nemo's "Make Link"?:** Nemo does have a seemingly similar functionality built-in, which is called "Make Link". **However, the only similarity is in name, not functionality.** Nemo's "Make Link" creates a link file to the object, whereas this Action creates a .desktop file to the object. The differences are obvious in use. For example, if you have a file (hello.txt), using Nemo's "Make Link" will result in a link file with the name "Link to hello.txt". When double clicking this link (to open with a text editor), the filename the text editor will show is incorrectly stated as "Link to hello.txt" rather than just "hello.txt". Even worse, if you happen to move this link to some other folder and then double click it, the path will also be wrong, incorrectly displaying the path to the link file itself rather than the path to the actual file. For example: "/path/to/hello.txt" vs "/path/to/my_folder/Link to hello.txt". **This does not happen when using this Action.** This Action uses .desktop files, which preserve the path of the actual file, as well as correctly identifying the name of the file. + +This following Actions should be paired for a complete package: +* create-link-desktop@DopeyDave +* create-link-here@DopeyDave (You Are Here) +* follow-desktop-link@DopeyDave + +Usage +----------- + +Right click on a file or folder. Select the new option "Create Link Here". diff --git a/create-link-here@DopeyDave/create-link-here@DopeyDave.nemo_action.in b/create-link-here@DopeyDave/create-link-here@DopeyDave.nemo_action.in new file mode 100644 index 00000000..262fcb96 --- /dev/null +++ b/create-link-here@DopeyDave/create-link-here@DopeyDave.nemo_action.in @@ -0,0 +1,7 @@ +[Nemo Action] +_Name=Create Link Here +_Comment=For the selected file/folder, create a link (.desktop file) here +Exec= +Icon-Name=emblem-symbolic-link +Selection=notnone +Extensions=any; diff --git a/create-link-here@DopeyDave/files/create-link-here@DopeyDave/create-link-here@DopeyDave.sh b/create-link-here@DopeyDave/files/create-link-here@DopeyDave/create-link-here@DopeyDave.sh new file mode 100755 index 00000000..2710c275 --- /dev/null +++ b/create-link-here@DopeyDave/files/create-link-here@DopeyDave/create-link-here@DopeyDave.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# Check if any files/folders are selected +if [ -z "$1" ]; then + echo "No file/folder selected." + exit 1 +fi + +# Get the target file or folder +TARGET="$1" + +# Debug note: +# To print to the system log (file: /var/log/syslog), +# in bash, use the following example: +# logger "Target: $TARGET" + +# If "\" char is in the string +# Note: Use [[double brackets]] +if [[ "$TARGET" == *\\* ]]; then + # Remove all ("//") "\" chars + TARGET="${TARGET//\\}" +fi + +# Extract the filename and path +FILENAME=$(basename "$TARGET") +DIRNAME=$(dirname "$TARGET") + +# Preserve the real filename, which could start with "." (hidden) +NAME_OF_FILE=$FILENAME + +# If the filename starts with a dot, prepend an underscore to the filename +# in order to make it visible on the Desktop +if [[ "$FILENAME" == .* ]]; then + FILENAME="_$FILENAME" +fi + +# Create a .desktop file in the same directory as the selected file/folder +# Note: If hidden ("."), "_" is pre-pended so file will be visible +# if it is moved to the Desktop +DESKTOP_FILE="${DIRNAME}/${FILENAME}.desktop" + +# Check if the .desktop file already exists in this folder +if [ -e "$DESKTOP_FILE" ]; then + echo "A .desktop file already exists for this item in this folder." + exit 1 +fi + +# Determine the icon based on the type of file or folder +if [ -d "$TARGET" ]; then + ICON="folder" +elif file --mime-type "$TARGET" | grep -q 'text/'; then + ICON="text" +elif file --mime-type "$TARGET" | grep -q 'application/pdf'; then + ICON="application-pdf" +elif file --mime-type "$TARGET" | grep -q 'image/'; then + ICON="image-x-generic" +elif file --mime-type "$TARGET" | grep -q 'audio/'; then + ICON="audio-x-generic" +elif file --mime-type "$TARGET" | grep -q 'video/'; then + ICON="video-x-generic" +else # Unknown type + ICON="application-octet-stream" +fi + +# Create the .desktop file content +echo "[Desktop Entry]" > "$DESKTOP_FILE" +echo "Name=$NAME_OF_FILE" >> "$DESKTOP_FILE" # Use real name of file (this will show "." files/folders correctly on Desktop) +echo "URL=file://$TARGET" >> "$DESKTOP_FILE" # URL format needed for Link type +echo "Icon=$ICON" >> "$DESKTOP_FILE" +echo "Terminal=false" >> "$DESKTOP_FILE" +echo "Type=Link" >> "$DESKTOP_FILE" # Type needs to be Link + +# Make the .desktop file executable +chmod +x "$DESKTOP_FILE" + +# Output complete +echo "Created .desktop link: $DESKTOP_FILE" diff --git a/create-link-here@DopeyDave/files/create-link-here@DopeyDave/icon.png b/create-link-here@DopeyDave/files/create-link-here@DopeyDave/icon.png new file mode 100644 index 00000000..858e1d0b Binary files /dev/null and b/create-link-here@DopeyDave/files/create-link-here@DopeyDave/icon.png differ diff --git a/create-link-here@DopeyDave/files/create-link-here@DopeyDave/metadata.json b/create-link-here@DopeyDave/files/create-link-here@DopeyDave/metadata.json new file mode 100644 index 00000000..9c8a12e6 --- /dev/null +++ b/create-link-here@DopeyDave/files/create-link-here@DopeyDave/metadata.json @@ -0,0 +1,7 @@ +{ + "description": "Create a link (shortcut) here for a file/folder", + "uuid": "create-link-here@DopeyDave", + "name": "Create a Link Here", + "author": "DopeyDave", + "version": "1.0" +} \ No newline at end of file diff --git a/create-link-here@DopeyDave/info.json b/create-link-here@DopeyDave/info.json new file mode 100644 index 00000000..a72bf873 --- /dev/null +++ b/create-link-here@DopeyDave/info.json @@ -0,0 +1,3 @@ +{ + "author": "DopeyDave" +} \ No newline at end of file