├── .gitignore ├── LICENSE ├── README.md ├── package └── PhpStorm: Open project.alfredworkflow └── src ├── find-project.sh └── lib └── workflowHandler.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2016 bchatard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PhpStorm: Open project 2 | ======================== 3 | 4 | Easily open your PhpStorm projects with Alfred2 workflow 5 | 6 | #### New version 7 | A new version is available: [JetBrains: Open project](https://github.com/bchatard/jetbrains-alfred-workflow) 8 | -------------------------------------------------------------------------------- /package/PhpStorm: Open project.alfredworkflow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bchatard/phpstorm-alfred-workflow/1d4b5577d39d737a1e6a5e8a238be558cc732754/package/PhpStorm: Open project.alfredworkflow -------------------------------------------------------------------------------- /src/find-project.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # include workflowHandler (https://github.com/markokaestner/bash-workflow-handler) 4 | . ./lib/workflowHandler.sh 5 | 6 | # Path to PhpStorm script 7 | PHPSTORM_SCRIPT="/usr/local/bin/pstorm" 8 | # XPath to projects location in other.xml 9 | XPATH_PROJECTS="//component[@name='RecentDirectoryProjectsManager']/option[@name='names']/map/entry/@key" 10 | XPATH_RECENT_PROJECTS="//component[@name='RecentDirectoryProjectsManager']/option[@name='recentPaths']/list/option/@value" 11 | # App Icon 12 | APP_ICON='fileicon:/Applications/PhpStorm.app' 13 | # Current nocasematch status 14 | CURRENT_NOCASEMATCH='off' 15 | 16 | ORIG_IFS=${IFS} 17 | 18 | ################################################################################ 19 | # Adds a result to the result array 20 | # Overloaded to manage icon as fileicon (remove if pull request is merged) 21 | # 22 | # $1 uid 23 | # $2 arg 24 | # $3 title 25 | # $4 subtitle 26 | # $5 icon 27 | # $6 valid 28 | # $7 autocomplete 29 | ############################################################################### 30 | addResult() 31 | { 32 | RESULT="$(xmlEncode "$3")$(xmlEncode "$4")" 33 | if [[ $5 =~ fileicon:* ]]; then 34 | icon=`echo $5 | sed -e 's/fileicon://g'` 35 | RESULT="${RESULT}$(xmlEncode "${icon}")" 36 | elif [[ $5 =~ filetype:* ]]; then 37 | icon=`echo $5 | sed -e 's/filetype://g'` 38 | RESULT="${RESULT}$(xmlEncode "${icon}")" 39 | else 40 | RESULT="${RESULT}$(xmlEncode "$5")" 41 | fi 42 | RESULT="${RESULT}" 43 | 44 | RESULTS+=("$RESULT") 45 | } 46 | 47 | ## 48 | # Retrieve project from PhpStorm configuration 49 | # return a string with paths separate by a = 50 | # 51 | # @return string 52 | getProjectsPath() 53 | { 54 | escapedHome=`echo $HOME | sed -e 's/[/]/\\\\\//g'` 55 | basePath="$(grep -F -m 1 'CONFIG_PATH =' ${PHPSTORM_SCRIPT})" 56 | basePath="${basePath#*\'}" 57 | basePath="${basePath%\'*}" 58 | optionsOther="${basePath}/options/other.xml" 59 | recentProjectDirectories="${basePath}/options/recentProjectDirectories.xml" 60 | 61 | if [ -r ${recentProjectDirectories} ]; then # v9 62 | projects=`xmllint --xpath ${XPATH_RECENT_PROJECTS} ${recentProjectDirectories}` 63 | projects=`echo ${projects} | sed -e 's/key=//g' -e 's/value=//g' -e 's/" "/;/g' -e 's/^ *//g' -e 's/ *$//g' -e 's/"//g' -e "s/[$]USER_HOME[$]/${escapedHome}/g"` 64 | echo ${projects} 65 | elif [ -r ${optionsOther} ]; then #v7 & v8 66 | projects=`xmllint --xpath ${XPATH_PROJECTS} ${optionsOther} 2>/dev/null` 67 | if [[ -z ${projects} ]]; then 68 | projects=`xmllint --xpath ${XPATH_RECENT_PROJECTS} ${optionsOther}` 69 | fi 70 | projects=`echo ${projects} | sed -e 's/key=//g' -e 's/value=//g' -e 's/" "/;/g' -e 's/^ *//g' -e 's/ *$//g' -e 's/"//g' -e "s/[$]USER_HOME[$]/${escapedHome}/g"` 71 | echo ${projects} 72 | fi 73 | } 74 | 75 | ## 76 | # Retrieve project name from project configuration 77 | # search project name in this file because project name can be different than folder name 78 | # ex: folder: my-project ; project name: My Private Project 79 | # 80 | # @return string 81 | extractProjectName() 82 | { 83 | nameFile="$1/.idea/.name" 84 | if [ -r ${nameFile} ]; then 85 | projectName=`cat ${nameFile}` 86 | echo ${projectName} 87 | fi 88 | } 89 | 90 | ## 91 | # Enable nocasematch 92 | enableNocasematch() 93 | { 94 | CURRENT_NOCASEMATCH=`shopt | grep 'nocasematch' | sed -e 's/nocasematch//' -e 's/^ *//g' -e 's/ *$//g' | tr -d '\011'` 95 | shopt -s nocasematch 96 | } 97 | 98 | ## 99 | # Restore nocasematch 100 | restoreNocasematch() 101 | { 102 | if [ "${CURRENT_NOCASEMATCH}" == "off" ]; then 103 | shopt -u nocasematch 104 | fi 105 | } 106 | 107 | ## 108 | # Check if PhpStorm app exists 109 | # return string if app not found 110 | # 111 | # @return string|void 112 | appExists () 113 | { 114 | runPath="$(grep -F -m 1 'RUN_PATH =' ${PHPSTORM_SCRIPT})" 115 | runPath="${runPath#*\'}" 116 | runPath="${runPath%\'*}" 117 | runPath="${runPath}/Contents/MacOS/phpstorm" 118 | if [[ ! -f "${runPath}" ]]; then 119 | echo "${runPath}" 120 | fi 121 | } 122 | 123 | ## 124 | # Entry point 125 | # return XML string for Alfred 126 | # 127 | # @return string 128 | findProjects() 129 | { 130 | # enable insensitive comparison 131 | enableNocasematch 132 | 133 | appPath=$(appExists) 134 | if [[ -z "${appPath}" ]]; then 135 | QUERY="$1" 136 | nbProject=0 137 | projectsPath="$(getProjectsPath)" 138 | if [[ ! -z "${projectsPath}" ]]; then 139 | IFS=';' 140 | read -a projectsPath<<<"${projectsPath}" 141 | IFS=$'' 142 | for projectPath in "${projectsPath[@]}"; do 143 | projectName=$(extractProjectName ${projectPath}) 144 | if [ -n "${projectName}" ] && [ "${projectName}" != "" ]; then 145 | if [[ ${projectName} == *${QUERY}* ]] || [[ -z "${QUERY}" ]]; then 146 | addResult ${projectName} ${projectPath} ${projectName} ${projectPath} ${APP_ICON} 'yes' ${projectName} 147 | ((nbProject++)) 148 | fi 149 | fi 150 | done 151 | 152 | # if there is no project display information 153 | if [ ${nbProject} -eq 0 ]; then 154 | addResult 'none' '' "No project match '${QUERY}'" "No project match '${QUERY}'" ${APP_ICON} 'yes' ${QUERY} 155 | fi 156 | else 157 | addResult 'none' '' "Can't find projects" "check configuration or contact developer" ${APP_ICON} 'yes' '' 158 | fi 159 | else 160 | addResult 'none' '' "Can't find projects" "Not a valid path: ${appPath}" ${APP_ICON} 'yes' '' 161 | fi 162 | 163 | # restore nocasematch value 164 | restoreNocasematch 165 | 166 | getXMLResults 167 | } 168 | 169 | # tests 170 | #getProjectsPath $1 171 | #findProjects $1 172 | #appExists 173 | 174 | IFS=${ORIG_IFS} -------------------------------------------------------------------------------- /src/lib/workflowHandler.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VPREFS="${HOME}/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/" 4 | NVPREFS="${HOME}/Library/Application Support/Alfred 2/Workflow Data/" 5 | 6 | RESULTS=() 7 | 8 | ################################################################################ 9 | # Adds a result to the result array 10 | # 11 | # $1 uid 12 | # $2 arg 13 | # $3 title 14 | # $4 subtitle 15 | # $5 icon 16 | # $6 valid 17 | # $7 autocomplete 18 | ############################################################################### 19 | addResult() { 20 | RESULT="$(xmlEncode "$3")$(xmlEncode "$4")$(xmlEncode "$5")" 21 | RESULTS+=("$RESULT") 22 | } 23 | 24 | ############################################################################### 25 | # Prints the feedback xml to stdout 26 | ############################################################################### 27 | getXMLResults() { 28 | echo "" 29 | 30 | # if [ "${#string[@]}" = "0" ]; then 31 | # echo "No results foundPlease try another search term" 32 | # fi 33 | 34 | for R in ${RESULTS[*]}; do 35 | echo "$R" | tr "\n" " " 36 | done 37 | 38 | echo "" 39 | } 40 | 41 | ############################################################################### 42 | # Escapes XML special characters with their entities 43 | ############################################################################### 44 | xmlEncode() { 45 | echo "$1" | sed -e 's/&/\&/g' -e 's/>/\>/g' -e 's/ "$PREFFILE" 105 | fi 106 | echo "$1=$2" >> "$PREFFILE" 107 | } 108 | 109 | ############################################################################### 110 | # Read a value for a given key from the workflow preferences 111 | # 112 | # $1 key 113 | # $2 non-volatile 0/1 114 | # $3 filename (optional, filename will be "settings" if not specified) 115 | ############################################################################### 116 | getPref() { 117 | local BUNDLEID=$(getBundleId) 118 | if [ "$2" = "0" ]; then 119 | local PREFDIR="${VPREFS}${BUNDLEID}" 120 | else 121 | local PREFDIR="${NVPREFS}${BUNDLEID}" 122 | fi 123 | 124 | if [ ! -d "$PREFDIR" ]; then 125 | return 126 | fi 127 | 128 | if [ -z "$3" ]; then 129 | local PREFFILE="${PREFDIR}/settings" 130 | else 131 | local PREFFILE="${PREFDIR}/$3" 132 | fi 133 | 134 | if [ ! -f "$PREFFILE" ]; then 135 | return 136 | fi 137 | 138 | local VALUE=$(sed "/^\#/d" "$PREFFILE" | grep "$1" | tail -n 1 | cut -d "=" -f2-) 139 | echo "$VALUE" 140 | } 141 | 142 | getLang() { 143 | defaults read .GlobalPreferences AppleLanguages | tr -d [:space:] | cut -c2-3 144 | } 145 | --------------------------------------------------------------------------------