Open
Description
Here's a version that allows for passing a third parameter describing which project the file belongs to. That way a part of the path can be replaced. It also decodes slashes etc. in the path.
#!/usr/bin/env bash
# PhpStorm URL Handler
# phpstorm://open?url=file://@file&line=@line
# phpstorm://open?file=@file&line=@line
#
# @license GPL
# @author Stefan Auditor <[email protected]>
# @author Petr 'PePa' Pavel <[email protected]>
input=${1}
# https://stackoverflow.com/a/37840948/465732
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
arg=$(urldecode "$input")
pattern=".*file(:\/\/|\=)(.*)&line=(.*)(&project=(.*))?"
# Get the file path.
file=$(echo "${arg}" | sed -r "s/${pattern}/\2/")
# Get the line number.
line=$(echo "${arg}" | sed -r "s/${pattern}/\3/")
# Project name for path replacement
project=$(echo "${arg}" | sed -r "s/${pattern}/\5/")
if [ -n "$project" ]; then
basePath="/home/myusername/projects"
declare -A paths
paths["project5.6"]="projectdirname/php-5.6"
file=$(echo "${file}" | sed -r "s#/var/www/app#${basePath}/${paths[$project]}#")
fi
# Check if phpstorm|pstorm command exist.
if type phpstorm > /dev/null; then
/usr/bin/env phpstorm --line "${line}" "${file}"
elif type pstorm > /dev/null; then
/usr/bin/env pstorm --line "${line}" "${file}"
fi
Metadata
Metadata
Assignees
Labels
No labels