Last active
December 19, 2015 22:28
-
-
Save jakerr/6027228 to your computer and use it in GitHub Desktop.
Retry the subl command when it fails to open the requested file.
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.