Skip to content

Instantly share code, notes, and snippets.

@maddouri
Created August 12, 2018 17:19
Show Gist options
  • Save maddouri/a28af3ea8bdbde1f656d16eebc87f9a3 to your computer and use it in GitHub Desktop.
Save maddouri/a28af3ea8bdbde1f656d16eebc87f9a3 to your computer and use it in GitHub Desktop.
A better "subl" command: Allows piping to Sublime Text
# 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