Last active
July 24, 2017 22:32
-
-
Save mislav/a4cbfe173c9ed835b900c264a247e1dc to your computer and use it in GitHub Desktop.
Open specific editor based on directory contents
This file contains hidden or 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
export EDITOR_XCODEPROJ='open -a XCode' | |
export EDITOR_TSCONFIG='code' | |
export EDITOR_DEFAULT='atom' | |
export EDITOR='magic-open' |
This file contains hidden or 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 | |
set -e | |
target="${1?}" | |
if [ -d "$target" ]; then | |
dir_contents="$(ls -a "$target")" | |
for editor_type in $(env | grep ^EDITOR_ | cut -d= -f1); do | |
matcher="${editor_type#EDITOR_}" | |
if [ "$matcher" != 'DEFAULT' ] && grep -iq "$matcher" <<<"$dir_contents"; then | |
exec ${!editor_type} "$target" | |
fi | |
done | |
fi | |
exec ${EDITOR_DEFAULT?} "$target" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment