Created
August 12, 2018 17:19
-
-
Save maddouri/a28af3ea8bdbde1f656d16eebc87f9a3 to your computer and use it in GitHub Desktop.
A better "subl" command: Allows piping 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
# a better "subl" command: | |
# allows piping to sublime text: | |
# open sublime text: | |
# subl [arguments] [files] | |
# subl ~/.bashrc | |
# or | |
# pipe output to sublime text: | |
# some_command | subl | |
# echo "Hello sublime pipe" | subl | |
# adapted from https://gist.github.com/nathforge/7120225 | |
function subl() { | |
# http://stackoverflow.com/a/2456870 | |
if [ -t 0 ]; then | |
/usr/bin/env subl $* | |
else | |
# http://stackoverflow.com/a/18593713 | |
FILENAME="$(mktemp)" | |
tee "${FILENAME}" > /dev/null | |
/usr/bin/env subl $* "${FILENAME}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment