diff --git a/core/core-os-osx.el b/core/core-os-osx.el index 387f220b1..c75291d89 100644 --- a/core/core-os-osx.el +++ b/core/core-os-osx.el @@ -51,6 +51,8 @@ (defadvice evil-visual-update-x-selection (around clobber-x-select-text activate) (unless (or (featurep 'mac) (featurep 'ns)) ad-do-it))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defun narf-open-with (&optional app-name path) "Send PATH to APP-NAME on OSX." (interactive) @@ -60,19 +62,26 @@ (buffer-file-name)))))) (command (format "open %s" (if app-name - (format "-a %s" (shell-quote-argument app-name)) + (format "-a %s %s" (shell-quote-argument app-name) path) (format "'%s'" path))))) (message "Running: %s" command) (shell-command command))) (defun narf-switch-to-iterm () (interactive) - (do-applescript "tell application \"iTerm2\" to activate")) + (do-applescript "tell application \"iTerm\" to activate")) (defun narf-switch-to-iterm-and-cd () (interactive) (narf:tmux-chdir nil t) (narf-switch-to-iterm)) +(defun narf-send-to-iterm (command &optional dont-run) + (when dont-run + (setq command (concat command " "))) + (do-applescript + (format "tell app \"iTerm\" to tell current session of current tab of first window to write text \"%s\"" + (s-replace "\"" "\\\"" command)))) + (provide 'core-os-osx) ;;; core-os-osx.el ends here diff --git a/core/lib/defuns-term.el b/core/lib/defuns-term.el new file mode 100644 index 000000000..b6bbe34c0 --- /dev/null +++ b/core/lib/defuns-term.el @@ -0,0 +1,30 @@ +;;; defuns-tmux.el + +(defun narf--send-to-tmux (command) + (shell-command (format "tmux send-keys %s" command))) + +(evil-define-interactive-code "" + "Ex tmux argument (a mix between and )" + :ex-arg shell + (list (when (evil-ex-p) (evil-ex-file-arg)))) + +;;;###autoload (autoload 'narf:send-to-tmux "defuns-term" nil t) +(evil-define-command narf:send-to-tmux (command &optional bang) + "Sends input to tmux. Use `bang' to append to tmux" + (interactive "") + (narf--send-to-tmux (format (if bang "C-u %s Enter" "%s") + (shell-quote-argument command))) + (when (evil-ex-p) + (message "[Tmux] %s" command))) + +;;;###autoload (autoload 'narf:send-to-iterm "defuns-term" nil t) +(when IS-MAC + (evil-define-command narf:send-to-iterm (command &optional bang) + "Sends input to tmux. Use `bang' to append to tmux" + (interactive "") + (narf-send-to-iterm command bang) + (when (evil-ex-p) + (message "[iTerm] %s" command)))) + +(provide 'defuns-tmux) +;;; defuns-tmux.el ends here diff --git a/core/lib/defuns-tmux.el b/core/lib/defuns-tmux.el deleted file mode 100644 index 4978723b1..000000000 --- a/core/lib/defuns-tmux.el +++ /dev/null @@ -1,35 +0,0 @@ -;;; defuns-tmux.el - -(defun narf--tmux-send (command) - (shell-command (format "tmux send-keys %s" command))) - -(evil-define-interactive-code "" - "Ex tmux argument (a mix between and )" - :ex-arg shell - (list (when (evil-ex-p) (evil-ex-file-arg)))) - -;;;###autoload (autoload 'narf:tmux-run "defuns-tmux" nil t) -(evil-define-command narf:tmux-run (&optional command bang) - "Sends input to tmux. Use `bang' to append to tmux" - (interactive "") - (narf--tmux-send (format (if bang "C-u %s Enter" "%s") - (shell-quote-argument command))) - (when (evil-ex-p) - (message "[Tmux] %s" command))) - -;;;###autoload (autoload 'narf:tmux-chdir "defuns-tmux" nil t) -(evil-define-command narf:tmux-chdir (&optional path bang) - "CDs in tmux using `narf/project-root'" - (interactive "") - (let ((dir (shell-quote-argument - (if (and path (not (s-blank? path))) - (if (file-directory-p path) - (file-truename path) - (error "Directory doesn't exist %s" path)) - (if bang default-directory (narf/project-root)))))) - (narf--tmux-send (format "C-u cd Space %s Enter" (shell-quote-argument dir))) - (when (evil-ex-p) - (message "[Tmux] cd %s" dir)))) - -(provide 'defuns-tmux) -;;; defuns-tmux.el ends here diff --git a/private/my-commands.el b/private/my-commands.el index c225560f1..0bb33903e 100644 --- a/private/my-commands.el +++ b/private/my-commands.el @@ -42,13 +42,12 @@ (exmap "settr[im]" 'narf:toggle-delete-trailing-whitespace) (exmap "snip[pets]" 'narf:yas-snippets) ; snip[!] (exmap "fi[nd]" 'narf:helm-swoop) -(exmap "t[mux]" 'narf:tmux-run) -(exmap "tcd" 'narf:tmux-chdir) (exmap "tsnip[pets]" 'narf:yas-file-templates) ; tsnip[!] -(exmap "term" 'narf-switch-to-iterm) (exmap "x" 'narf:scratch-buffer) + (after! flycheck (exmap "er[rors]" (λ (flycheck-buffer) (flycheck-list-errors)))) + (after! workgroups2 (exmap "sl[oad]" 'narf:load-session) (exmap "ss[ave]" 'narf:save-session) @@ -63,5 +62,15 @@ (exmap "k[ill]w" 'wg-kill-workgroup) (exmap "k[ill]ow" 'narf:kill-other-workgroups)) +(cond (IS-MAC + (exmap "t[erm]" 'narf:send-to-iterm) + (exmap "tcd" (λ (narf:send-to-iterm (format "cd '%s'" default-directory))))) + (IS-LINUX + (exmap "t[mux]" 'narf:send-to-tmux) + (exmap "tcd" (λ (narf:send-to-tmux (format "cd '%s'" default-directory))))) + (IS-WINDOWS + ;; TODO Eshell integration + )) + (provide 'my-commands) ;;; my-commands.el ends here