2018-07-11 21:25:17 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# To set this up, open iTerm2 -> Preferences -> Profiles -> Advanced
|
|
|
|
# In the "Semantic History" section, choose "Always run command..." from the
|
|
|
|
# dropdown and set the input text to:
|
2018-07-17 00:26:32 +02:00
|
|
|
# `~/dotfiles/emacs.d/open-from-iterm.sh \1`
|
2018-07-11 21:25:17 +02:00
|
|
|
|
2018-07-17 00:26:32 +02:00
|
|
|
# Alias applications since $PATH is unavailable
|
2018-07-11 21:25:17 +02:00
|
|
|
emacs=/usr/local/bin/emacsclient
|
|
|
|
grep=/usr/local/bin/ggrep
|
2018-07-17 00:26:32 +02:00
|
|
|
tmux=/usr/local/bin/tmux
|
|
|
|
realpath=/Users/wpcarro/.nix-profile/bin/realpath
|
2018-07-11 21:25:17 +02:00
|
|
|
|
|
|
|
e() {
|
|
|
|
# Useful debugger when paired with `tail -f /tmp/debug.log`
|
|
|
|
echo "$@" >>/tmp/debug.log
|
|
|
|
}
|
|
|
|
|
2018-07-17 00:26:32 +02:00
|
|
|
# Need to query Tmux since iTerm's \5 variable doesn't work as expected with
|
|
|
|
# Tmux.
|
|
|
|
pwd=$($tmux display -pF '#{pane_current_path}')
|
2018-07-11 21:25:17 +02:00
|
|
|
cd "$pwd" || exit
|
2018-07-17 00:26:32 +02:00
|
|
|
path=$($realpath "$1")
|
2018-07-11 21:25:17 +02:00
|
|
|
|
|
|
|
# This is a bit of a hack, but we cannot rely on iTerm to regex our paths
|
|
|
|
file=$($grep -P -o '^[^:]+' <<<"$path")
|
|
|
|
number=$($grep -P -o '(?<=:)[0-9]+(?=:[0-9]+:$)' <<<"$path")
|
|
|
|
|
2018-07-17 00:26:32 +02:00
|
|
|
# Debugging
|
2018-07-11 21:25:17 +02:00
|
|
|
e "file: $file"
|
|
|
|
e "number: $number"
|
|
|
|
|
|
|
|
if ! [ -z "$number" ]; then
|
2018-07-17 00:26:32 +02:00
|
|
|
$emacs -n -e "(find-file \"$file\")" "(goto-line $number)"
|
|
|
|
else
|
|
|
|
$emacs -n -e "(find-file \"$file\")"
|
2018-07-11 21:25:17 +02:00
|
|
|
fi
|