Created
January 27, 2019 11:41
-
-
Save ziishaned/18a478b819de0deda62969bd9395640d to your computer and use it in GitHub Desktop.
Open file links in sublime from iTerm
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/sh | |
pwd=$1 | |
file=$2 | |
regex='https?://([a-z0-9A-Z]+(:[a-zA-Z0-9]+)?@)?[-a-z0-9A-Z\-]+(\.[-a-z0-9A-Z\-]+)*((:[0-9]+)?)(/[a-zA-Z0-9;:/\.\-_+%~?&@=#\(\)]*)?' | |
perl -e "if ( \"$file\" =~ m|$regex|) { exit 0 } else { exit 1 }" | |
if [ $? -ne 0 ]; then | |
# if it's not a url, try splitting by ':' | |
arr=($(echo $2 | tr ':' "\n")) | |
file=${arr[0]} | |
lineno=${arr[1]:-$3} | |
colno=${arr[2]:-${3##*:}} | |
[ -e "$file" ] || file=${pwd}/${file} | |
fi | |
file "$file" | grep -q "text" | |
if [ $? -ne 0 ]; then | |
/usr/bin/open $file | |
else | |
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl ${file}${lineno:+:${lineno}}${colno:+:${colno}} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preferences > Profiles > Default > Advanced
Semantic History
chooseRun command...