Skip to content

Instantly share code, notes, and snippets.

@jakerr
Last active December 19, 2015 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakerr/6027228 to your computer and use it in GitHub Desktop.
Save jakerr/6027228 to your computer and use it in GitHub Desktop.
Retry the subl command when it fails to open the requested file.
#!/bin/bash
#
# Review this script before use and use at your own risk.
#
try_subl() {
echo "" > $temp_log
# Start recording system log.
# Start tail with 0 lines, and follow mode so we just
# get lines that occur while we try to subl.
tail -n0 -f /private/var/log/system.log >> $temp_log &
tail_pid=$!
# Try subl
subl $@ &
try_subl_pid=$!
sleep 1
# Kill the tail
last_logs=`cat $temp_log`
kill $tail_pid
# Look for the symptom in the log lines generated.
subl_fail=`echo "${last_logs}"| grep -c "NSMachPort handlePortMessage.*dropping incoming DO"`
if [[ ! $subl_fail == 0 ]]; then
echo "subl failed, will retry."
kill $try_subl_pid
try_subl $@
else
wait $try_subl_pid
fi
}
temp_log=`mktemp /tmp/subl_log_tail.XXXXXX`
try_subl $@ 2>/dev/null
rm $temp_log
@jakerr
Copy link
Author

jakerr commented Jul 18, 2013

Review the script before use

Use at your own risk.

What

The subl command on OSX often fails to open the file: sublimehq/sublime_text#27 (comment) The developer hasn't given the bug any attention in years so here is a hacky retry script in bash to work around it. I'm not the most proficient bash scripter so please feel free to point out anything that could be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment