Skip to content

Instantly share code, notes, and snippets.

@young40
Created January 3, 2019 11:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save young40/8813cb05c672f7a06804af2164f2af68 to your computer and use it in GitHub Desktop.
Save young40/8813cb05c672f7a06804af2164f2af68 to your computer and use it in GitHub Desktop.
open file in Emacs or open it diectly
#!/bin/bash
# exec &> ~/logfile.txt
# In iTerm2 Session preferences <Advanced> pane setup Semantic History to:
#
# [Run coprocess...]
# ~/dot/item2_open_file_in_emacs.sh +\2 \1
if [[ $1 == "+" ]]; then
shift
fi
openInFinder()
{
ext=${1##*.}
extArray=(
"png"
"jpg"
"pdf"
"tps"
)
if [ "$ext" = "mp3" ]; then
afplay $1
exit
fi
for ex in ${extArray[@]}
do
if [ "$ext" = "$ex" ]; then
open $1
exit
fi
done
if [ -d "$1" ]; then
open $1
exit
fi
}
openInFinder $1
openInFinder $2
if ! (/usr/local/bin/emacsclient --eval "t" 2> /dev/null > /dev/null)
then
nohup /Applications/Emacs.app/Contents/MacOS/Emacs --chdir "${PWD}" $1 $2 &
else
/usr/local/bin/emacsclient -n $1 $2
fi
@randomwangran
Copy link

cool!

@randomwangran
Copy link

if ! (/usr/local/bin/emacsclient --eval "t" 2> /dev/null > /dev/null)

if ! (/usr/local/bin/emacsclient --eval "t" 2&1> /dev/null) ?

not sure...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment