Skip to content

Instantly share code, notes, and snippets.

@p1-olm
Last active June 12, 2017 10:19
Show Gist options
  • Save p1-olm/8257427dbe89633b2381044b8a39c099 to your computer and use it in GitHub Desktop.
Save p1-olm/8257427dbe89633b2381044b8a39c099 to your computer and use it in GitHub Desktop.
Allow piping to Sublime Text on Linux. Doesn't interfere with normal use.
#!/bin/bash
# Allow piping to Sublime Text. Doesn't interfere with normal use.
# Is stdin a terminal?
if test -t 0; then
# Stdin is a terminal.
# Open sublime normally.
/opt/sublime_text/sublime_text "$@"
else
# Stdin is not a terminal, it must be a pipe.
# Pipe stdin to a temporary file, and open it in sublime.
FILENAME=$(mktemp)
cat >"$FILENAME" && /opt/sublime_text/sublime_text "$FILENAME" "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment