Skip to content

Instantly share code, notes, and snippets.

@ozh
Last active April 12, 2026 20:45
Show Gist options
  • Select an option

  • Save ozh/3a15430a1d60e49d7852359c6bc4de42 to your computer and use it in GitHub Desktop.

Select an option

Save ozh/3a15430a1d60e49d7852359c6bc4de42 to your computer and use it in GitHub Desktop.
Open Notepad++ from BASH

npp - Notepad++ wrapper for Git Bash

Open files in Notepad++ from Git Bash, handling both Unix and Windows paths.

Usage

npp                        # Launch Notepad++
npp /e/path/to/file.php    # Open file (Unix path)
npp anything\weird         # Suspicious path → reads clipboard instead

Install

  1. Save the script as ~/npp
  2. chmod +x ~/npp
  3. Add to ~/.bashrc: alias npp='~/npp'
#!/bin/sh
open_npp() {
echo "Opening: $1"
e:/utils/Notepad++/notepad++.exe "$1" &
}
# No argument → just launch Notepad++
if [ -z "$1" ]; then
e:/utils/Notepad++/notepad++.exe &
exit 0
fi
# Valid unix path or simple filename (no backslash) → open directly
if ! echo "$1" | grep -q '\\'; then
open_npp "$1"
exit 0
fi
# Suspicious path (contains backslash) → try clipboard
echo "Suspicious path, trying clipboard instead..."
clipboard=$(powershell.exe -Command "Get-Clipboard" 2>/dev/null | tr -d '\r')
# Match "in E:\foo\bar.php on line 92" or just "E:\foo\bar.php"
filepath=$(echo "$clipboard" | grep -oP '(?<=in )[A-Za-z]:\\[^\s]+(?=\s+on line)' \
|| echo "$clipboard" | grep -oP '[A-Za-z]:\\[^\s]+')
if [ -z "$filepath" ]; then
echo "No valid path found in clipboard."
exit 1
fi
open_npp "$(cygpath -u "$filepath")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment