diff options
author | William Carroll <wpcarro@gmail.com> | 2018-07-11T19·25-0400 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2018-07-19T16·00-0400 |
commit | 4ccfe6238e6164a9b938270692fbc6cdca349b29 (patch) | |
tree | f20744112c2cbfa09e0084c12c988cabe4787732 | |
parent | 8e9aa65760f16ea037cff383b56059e04d622bf8 (diff) |
Open files in Emacs from iTerm w/ Semantic History
Finally cobbled together a solution... See the comments in the file for setup instructions.
-rwxr-xr-x | emacs.d/open-from-iterm.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/emacs.d/open-from-iterm.sh b/emacs.d/open-from-iterm.sh new file mode 100755 index 000000000000..e8857a1afbb4 --- /dev/null +++ b/emacs.d/open-from-iterm.sh @@ -0,0 +1,38 @@ +#!/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: +# `~/dotfiles/emacs.d/open-from-iterm.sh \1 \2` + +# NOTE: need to get $PATH set in here +# NOTE: these don't get forwarded into subshells +# # Alias applications since $PATH is unavailable +emacs=/usr/local/bin/emacsclient +grep=/usr/local/bin/ggrep +# tmux=/usr/local/bin/tmux +# realpath=/Users/wpcarro/.nix-profile/bin/realpath + + +e() { + # Useful debugger when paired with `tail -f /tmp/debug.log` + echo "$@" >>/tmp/debug.log +} + +# Need to use tmux here since \5 doesn't work as expected with Tmux. +pwd=$(/usr/local/bin/tmux display -pF '#{pane_current_path}') +cd "$pwd" || exit +path=$(/Users/wpcarro/.nix-profile/bin/realpath "$1") + +# 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") + +e "file: $file" +e "number: $number" + +$emacs -n -e "(find-file \"$file\")" + +if ! [ -z "$number" ]; then + $emacs -n -e "(goto-line $number)" +fi |