-
-
Save leahcim/ba84686f41d2daa6316b to your computer and use it in GitHub Desktop.
Launch Notepad++ from the shell while automatically detecting file type for syntax highlighting, even if file extension is missing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 9th July 2014 | |
lang() { | |
lang= | |
if [ -f "$1" ]; then | |
# keep reading until $line non empty | |
# ':' means "Do Nothing" | |
while read line && [ -z "$line" ]; do :; done < "$1" | |
case $line in | |
# if shebang present, read language from it | |
\#\!/*) | |
#!/usr/bin/python => python | |
#!/usr/bin/env python => python | |
#!/usr/bin/env python -c => python | |
lang=$(echo "$line" | sed 's#.*/##;s/\s\+-.*//;s/.*\s//'); | |
if [ "$lang" == "sh" ]; then | |
lang=bash | |
fi | |
;; | |
# otherwise, if '<' and '>' present, it's xml | |
*\<*\>*) | |
lang=xml | |
;; | |
%YAML*) | |
lang=yaml | |
;; | |
*) | |
lang= | |
;; | |
esac | |
fi | |
echo $lang | |
} | |
LANG=$(lang "$1") | |
if [ -n "$LANG" ]; then | |
L=-l$LANG | |
else | |
L= | |
fi | |
cmd.exe //c start "" "C:\Program Files\Notepad++\notepad++.exe" $L "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment