How to open gitg via nautilus

Is there a way to quickly open GitG or another VCS app through Nautilus?

For example, a Ctrl+Shift+comma shortcut to open GitG in the current folder?

Hi Sabri,

you can add a custom script with keyboard shortcut like this

mkdir -p ~/.local/share/nautilus/scripts
echo "#!/bin/bash
gitg \$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" > ~/.local/share/nautilus/scripts/gitg.sh
chmod +x ~/.local/share/nautilus/scripts/gitg.sh
mkdir -p ~/.config/nautilus/
echo "<Control>less gitg.sh" > ~/.config/nautilus/scripts-accels

The shortcut in ~/.config/nautilus/scripts-accels differs depending on what symbol you would type when pressing shift + comma, so might need to adjust that. Potential names for such keypresses can be found in gdk/gdkkeysyms.h · main · GNOME / gtk · GitLab

After some iterations with Claude AI

Content of the gitg.sh

#!/bin/bash

# Use selected item if available, otherwise use current directory
TARGET="${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS:-$NAUTILUS_SCRIPT_CURRENT_URI}"
TARGET="${TARGET#file://}"
TARGET=$(printf '%b' "${TARGET//%/\\x}")

# If it's a file, get the parent directory.
[ -f "$TARGET" ] && TARGET=$(dirname "$TARGET")

cd "$TARGET" || exit 1

if ! git rev-parse --git-dir > /dev/null 2>&1; then
    zenity --error --text="This directory is not a git repository!\n\nDirectory: $TARGET" --width=300
    exit 1
fi

# run gitg
flatpak run org.gnome.gitg . >/dev/null 2>&1 &

Content of the scripts-accels

<Alt>M gitg.sh