Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions create-link-here@DopeyDave/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 1.0

* Initial Release
21 changes: 21 additions & 0 deletions create-link-here@DopeyDave/README.md
Original file line number Diff line number Diff line change
@@ -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".
7 changes: 7 additions & 0 deletions create-link-here@DopeyDave/[email protected]_action.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Nemo Action]
_Name=Create Link Here
_Comment=For the selected file/folder, create a link (.desktop file) here
Exec=<create-link-here@DopeyDave/[email protected] "%F">
Icon-Name=emblem-symbolic-link
Selection=notnone
Extensions=any;
Original file line number Diff line number Diff line change
@@ -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"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions create-link-here@DopeyDave/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"author": "DopeyDave"
}