feat(macos): add 'open in new iTerm window' command

Plus keybinds on '<leader> o I'.

Close: #6318
Co-authored-by: brorbw <brorbw@users.noreply.github.com>
This commit is contained in:
Henrik Lissner 2022-06-21 18:08:02 +02:00
parent db3ca52ed6
commit ec2062f517
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
3 changed files with 29 additions and 5 deletions

View file

@ -261,7 +261,8 @@
:desc "Send project to Transmit" "U" #'+macos/send-project-to-transmit
:desc "Send to Launchbar" "l" #'+macos/send-to-launchbar
:desc "Send project to Launchbar" "L" #'+macos/send-project-to-launchbar
:desc "Open in iTerm" "i" #'+macos/open-in-iterm)
:desc "Open in iTerm" "i" #'+macos/open-in-iterm
:desc "Open in new iTerm window" "I" #'+macos/open-in-iterm-new-window)
(:when (featurep! :tools docker)
:desc "Docker" "D" #'docker)
(:when (featurep! :email mu4e)

View file

@ -628,7 +628,8 @@
:desc "Send project to Transmit" "U" #'+macos/send-project-to-transmit
:desc "Send to Launchbar" "l" #'+macos/send-to-launchbar
:desc "Send project to Launchbar" "L" #'+macos/send-project-to-launchbar
:desc "Open in iTerm" "i" #'+macos/open-in-iterm)
:desc "Open in iTerm" "i" #'+macos/open-in-iterm
:desc "Open in new iTerm window" "I" #'+macos/open-in-iterm-new-window)
(:when (featurep! :tools docker)
:desc "Docker" "D" #'docker)
(:when (featurep! :email mu4e)

View file

@ -1,6 +1,8 @@
;;; os/macos/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +macos-defaults (action &rest args)
(apply #'doom-call-process "defaults" action args))
(defun +macos-open-with (&optional app-name path)
"Send PATH to APP-NAME on OSX."
(interactive)
@ -18,12 +20,29 @@
(message "Running: %s" command)
(shell-command command)))
;;;###autoload
(defmacro +macos--open-with (id &optional app dir)
`(defun ,(intern (format "+macos/%s" id)) ()
(interactive)
(+macos-open-with ,app ,dir)))
(defmacro +macos--open-with-iterm (id &optional dir newwindow?)
`(defun ,(intern (format "+macos/%s" id)) ()
(interactive)
(letf! ((defun read-newwindows ()
(cdr (+macos-defaults
"read" "com.googlecode.iterm2" "OpenFileInNewWindows")))
(defun write-newwindows (bool)
(+macos-defaults
"write" "com.googlecode.iterm2" "OpenFileInNewWindows"
"-bool" (if bool "true" "false"))))
(let ((newwindow?
(if newwindow? (not (equal (read-newwindows) "1")))))
(when newwindow?
(write-newwindows t))
(unwind-protect (+macos-open-with "iTerm" ,dir)
(when newwindow?
(write-newwindows nil)))))))
;;;###autoload (autoload '+macos/open-in-default-program "os/macos/autoload" nil t)
(+macos--open-with open-in-default-program)
@ -48,4 +67,7 @@
(or (doom-project-root) default-directory))
;;;###autoload (autoload '+macos/open-in-iterm "os/macos/autoload" nil t)
(+macos--open-with open-in-iterm "iTerm" default-directory)
(+macos--open-with-iterm open-in-iterm default-directory)
;;;###autoload (autoload '+macos/open-in-iterm-new-window "os/macos/autoload" nil t)
(+macos--open-with-iterm open-in-iterm-new-window default-directory t)