Skip to content

Instantly share code, notes, and snippets.

@handlename
Created May 20, 2013 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save handlename/5613691 to your computer and use it in GitHub Desktop.
Save handlename/5613691 to your computer and use it in GitHub Desktop.
(defun my:chomp (str)
(replace-regexp-in-string "[\n\r]+$" "" str))
(defun my:git-project-p ()
(string=
(my:chomp
(shell-command-to-string "git rev-parse --is-inside-work-tree"))
"true"))
(defun my:tmux-do-command-for-file (filepath command)
(progn
(shell-command
(format "tmux new-window 'cd %s; %s -- %s'"
(file-name-directory filepath)
command
(file-name-nondirectory filepath)))))
(defun my:tmux-do-command-in-git-project (command)
(if (my:git-project-p)
(my:tmux-do-command-for-file buffer-file-name command)
(progn
(message "not in git repository.")
nil)))
(defun my:open-iterm ()
(shell-command (format "open -a iTerm")))
(defun my:git-diff-current-file ()
(interactive)
(if (my:tmux-do-command-in-git-project "git diff")
(my:open-iterm)))
(defun my:tig-blame-current-file ()
(interactive)
(if (my:tmux-do-command-in-git-project "tig blame")
(my:open-iterm)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment