Last active
March 31, 2021 08:41
-
-
Save theasta/863ba1bceca7c3add0f1 to your computer and use it in GitHub Desktop.
Download and open a file at a specific line and column
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 | |
# $1 has to match this pattern: http://example.com/file.js:3:10 | |
# First get back the url, the line and the column | |
regex="(https?:.*):([0-9]+):([0-9]+)" | |
dir="/tmp/" | |
[[ $1 =~ $regex ]] | |
url="${BASH_REMATCH[1]}" | |
line="${BASH_REMATCH[2]}" | |
col="${BASH_REMATCH[3]}" | |
# Then get back the filename | |
AFTER_SLASH=${url##*/} | |
filename="${dir}${AFTER_SLASH%%\?*}" | |
if [ ! -f ${filename} ]; then | |
pushd ${dir} | |
wget ${url} | |
popd | |
fi | |
code -g ${filename}:${line}:${col} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment