UP | HOME

Gnome Open Shell Here script that can deal with special characters


PDF (drucken)

The most painful missing piece in Gnome Nautilus compared to KDE Dolphin is clicking F4 to open a shell for the current folder. As a workaround I used a script from nixCraft, but that fails with folders that contain special characters like [, because the folder names are URL escaped.

Today I finally snapped and fixed the script:

#!/run/current-system/profile/bin/bash
# This script either opens in the current directory, 
# or in the selected directory

# thanks for the urldecoder goes to to https://stackoverflow.com/a/37840948
# license: cc by-sa (as this is stackoverflow)
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
base="$(echo $(urldecode "$NAUTILUS_SCRIPT_CURRENT_URI") | cut -d / -f3-)"
if [ -z "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
     dir="$base"
else 
     while [ ! -z "$1" -a ! -d "$base/$1" ]; do shift; done
     dir="$base/$1"
fi

gnome-terminal --working-directory="${dir}"

Save this into the file ~/.local/share/nautilus/scripts/Open Shell Here and make it executable, and you get a scripts menu entry in your right-click menu that still opens the right folder if you have untypical folder names.

For the lazy/overly trusting:

echo '#!/run/current-system/profile/bin/bash
# This script either opens in the current directory, 
# or in the selected directory

# thanks for the urldecoder goes to to https://stackoverflow.com/a/37840948
# license: cc by-sa (as this is stackoverflow)
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
base="$(echo $(urldecode "$NAUTILUS_SCRIPT_CURRENT_URI") | cut -d / -f3-)"
if [ -z "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
     dir="$base"
else 
     while [ ! -z "$1" -a ! -d "$base/$1" ]; do shift; done
     dir="$base/$1"
fi

gnome-terminal --working-directory="${dir}"
' > "$HOME/.local/share/nautilus/scripts/Open Shell Here"
chmod +x "$HOME/.local/share/nautilus/scripts/Open Shell Here"

That’s it. Have fun!

Date: 2020-03-03 Di 00:00

Author: ArneBab

Validate