-
-
Save nietonfir/8ae3c323cb6e339301bbce1fc78f00ac to your computer and use it in GitHub Desktop.
Allow piping to Sublime Text on Linux. Doesn't interfere with normal use.
This file contains hidden or 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 | |
# Allow piping to Sublime Text. Doesn't interfere with normal use. | |
subl=/usr/bin/subl | |
# Is stdin a terminal? | |
if test -t 0; then | |
# Stdin is a terminal. | |
# Open sublime normally. | |
$subl "$@" | |
else | |
# See https://stackoverflow.com/a/31035834/838733 | |
TMPDIR=${TMPDIR:-/tmp} # default to /tmp if TMPDIR isn't set | |
F=$(mktemp $TMPDIR/subl-XXXXXXXX) | |
cat >| $F # use >| instead of > if you set noclobber in bash | |
$subl $F | |
sleep .3 # give subl a little time to open the file | |
rm -f $F # file will be deleted as soon as subl closes it | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment