Skip to content

Instantly share code, notes, and snippets.

@theasta
Last active March 31, 2021 08:41
Show Gist options
  • Save theasta/863ba1bceca7c3add0f1 to your computer and use it in GitHub Desktop.
Save theasta/863ba1bceca7c3add0f1 to your computer and use it in GitHub Desktop.
Download and open a file at a specific line and column
#!/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