Created
November 3, 2014 12:48
-
-
Save anonymous/1534e6ecd14c8e8c56ca to your computer and use it in GitHub Desktop.
Add good bash to sublime_text
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 | |
SUBL_PATH="$1" | |
USER_PATH="$2" | |
PACKAGE_NAME="TextMateBasedBash" | |
SYNTAX_NAME="Shell Script Textmate (Bash)" | |
die() { | |
echo "$1" 1>&2 | |
exit 1 | |
} | |
defaults() { | |
[ -z "$SUBL_PATH" ] && SUBL_PATH="/opt/sublime_text_3" | |
[ -z "$USER_PATH" ] && USER_PATH="$HOME/.config/sublime-text-3" | |
} | |
verify() { | |
PACKAGE_PATH="$USER_PATH/Packages/$PACKAGE_NAME" | |
[ -d "$SUBL_PATH" ] || die "Couldn't find sublime dir at '$SUBL_PATH'. Please supply this as the first argument" | |
[ -d "$USER_PATH" ] || die "Couldn't find sublime user config at '$USER_PATH'. Please supply this as the second argument" | |
[ -d "$PACKAGE_PATH" ] && die "It seems you already have this package. Delete '$PACKAGE_PATH' to regenerate" | |
} | |
generate() { | |
echo "Unpacking..." | |
mkdir -p "$PACKAGE_PATH" | |
unzip "$SUBL_PATH/Packages/ShellScript.sublime-package" -d "$PACKAGE_PATH/" \ | |
|| die "Failed to unpack the package" | |
echo "Downloading TextMate stuff..." | |
wget -O- https://raw.githubusercontent.com/textmate/shellscript.tmbundle/master/Syntaxes/Shell-Unix-Bash.tmLanguage \ | |
> "$PACKAGE_PATH/Shell-Unix-Generic.tmLanguage" \ | |
|| die "Failed to download the TextMate syntax" | |
echo "Modifying..." | |
mv "$PACKAGE_PATH/Shell-Unix-Generic.tmLanguage" "$PACKAGE_PATH/Shell-Unix-Generic.tmLanguage.old" | |
cat "$PACKAGE_PATH/Shell-Unix-Generic.tmLanguage.old" \ | |
| sed -r "s|<string>Shell Script \\(Bash\\)</string>|<string>$SYNTAX_NAME</string>|" \ | |
> "$PACKAGE_PATH/Shell-Unix-Generic.tmLanguage" \ | |
|| die "Failed to setup the syntax name" | |
rm "$PACKAGE_PATH/Shell-Unix-Generic.tmLanguage.old" | |
echo "Done." | |
} | |
main() { | |
defaults | |
verify | |
generate | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment