term.lisp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. (in-package :stumpwm)
  2. (defvar *term-execute-flag* "-e")
  3. ;;;
  4. ;;; Xterm
  5. ;;;
  6. (defvar *xterm-command* "xterm")
  7. (defvar *xterm-big-command*
  8. (join '("exec" "xterm" "-fa" "Monospace" "-fs" "24")))
  9. (defvar *xterm-no-scrollbar* "+sb")
  10. (defvar *xterm-theme-dark* "-bg black -fg white")
  11. (defvar *xterm-theme-light* "-bg white -fg black")
  12. (defun xterm-command (&key
  13. (color (if dark-theme "dark" "light"))
  14. (command nil)
  15. (title nil)
  16. (font nil)
  17. (scrollbar nil)
  18. (lines 4096))
  19. (join `(,*xterm-command*
  20. ;; Make sure XTerm terminal size is appropriate for current StumpWM frame.
  21. ,@(if font
  22. font
  23. (if (small-framep)
  24. '("-fa" "Monospace" "-fs" "8")
  25. '()))
  26. "-sl" ,(write-to-string lines)
  27. ,(if scrollbar "-sb" *xterm-no-scrollbar*)
  28. ,(if (string= color "light") *xterm-theme-light* *xterm-theme-dark*)
  29. ,@(if title `("-title" ,title) '())
  30. ,@(if command `("-e" ,command) '()))))
  31. (defcommand run-xterm-command (cmd &optional collect-output-p)
  32. ((:shell "/bin/sh -c "))
  33. "Run the specified shell command in XTerm."
  34. (run-prog *shell-program*
  35. :args (list "-c" (join (list "/home/oleg/.guix-profile/bin/xterm -name" cmd "-e" cmd)))
  36. :wait nil))
  37. (defcommand run-or-raise-xterm () ()
  38. "Start or focus XTerm."
  39. (run-or-raise (xterm-command :lines 4096) '(:class "XTerm")))
  40. (defcommand run-xterm-named (title) ((:string "title: "))
  41. "Start or focus XTerm."
  42. (run-shell-command (xterm-command :color (if dark-theme "dark" "light")
  43. :title title
  44. :scrollbar t)))
  45. (defcommand run-xterm () ()
  46. "Start or focus XTerm."
  47. (run-prog *shell-program*
  48. :args (list "-c" (xterm-command))
  49. :wait nil))
  50. (defcommand run-xterm-light () ()
  51. (run-prog *shell-program*
  52. :args (list "-c" (xterm-command :scrollbar t :lines 4096 :color "light"))
  53. :wait nil))
  54. (defcommand xterm-dark-no-scrollbar () ()
  55. "Start or focus XTerm."
  56. (run-shell-command (xterm-command :color (if dark-theme "light" "dark"))))
  57. (defcommand xterm-name (cmd &optional collect-output-p)
  58. ((:string "window name: "))
  59. "Run the specified shell command in XTerm."
  60. (run-prog *shell-program*
  61. :args (list "-c" (join (list "xterm -name" cmd)))
  62. :wait nil))
  63. (defcommand xterm-big () ()
  64. "Start XTerm with big fonts."
  65. (run-shell-command *xterm-big-command*))
  66. (defcommand xterm-big-screen () ()
  67. "Start XTerm with big fonts."
  68. (run-shell-command
  69. (concat *xterm-big-command* " -e screen")))
  70. (defcommand run-alacritty () ()
  71. "Start or focus Alacritty."
  72. (run-prog *shell-program*
  73. :args (list "-c" "alacritty")
  74. :wait nil))
  75. (defcommand run-or-raise-alacritty () ()
  76. "Start or focus Alacritty."
  77. (run-or-raise "alacritty" '(:class "Alacritty")))
  78. (defcommand run-terminal () ()
  79. "Start terminal emulator."
  80. (if (string-equal (screen-display-string (current-screen)) "DISPLAY=:2.0")
  81. (run-xterm)
  82. (run-alacritty)))
  83. (defcommand run-or-raise-terminal () ()
  84. "Start of focus terminal emulator."
  85. (if (string-equal (screen-display-string (current-screen)) "DISPLAY=:2.0")
  86. (run-or-raise-xterm)
  87. (run-or-raise-alacritty)))
  88. ;;;
  89. ;;; St
  90. ;;;
  91. (defvar *st-command* "exec st")
  92. (defvar *st-exec-flag* "-e")
  93. (defvar *st-font* "Monospace:size=12")
  94. (defvar *st-font-flag* "-f")
  95. (defcommand st () ()
  96. "Start st."
  97. (run-shell-command "st -f 'Monospace:size=12'"))
  98. (defcommand st-tmux () ()
  99. "Start st with tmux."
  100. (run-shell-command "st -f 'Monospace:size=12' -e tmux"))
  101. ;;;
  102. ;;; XFCE
  103. ;;;
  104. (defcommand xfce-terminal () ()
  105. (run-shell-command "xfce4-terminal --color-bg=black"))
  106. (defcommand run-or-raise-xfce-terminal () ()
  107. (run-or-raise "xfce4-terminal --color-bg=black"
  108. '(:class "Xfce4-terminal")))
  109. ;;;
  110. ;;; Screen
  111. ;;;
  112. (defcommand screen
  113. (session &optional collect-output-p)
  114. ((:string "session name: "))
  115. "Run `screen' session."
  116. (run-prog *shell-program*
  117. :args
  118. (list "-c"
  119. (join (list "env" "STY=" ; Do not complain `$STY' in `screen'.
  120. "xterm" "-title" session
  121. "-e" "screen" "-S" session)))
  122. :wait nil))
  123. ;;;
  124. ;;; Wrappers
  125. ;;;
  126. (defun term-shell-command (command &key
  127. (terminal 'alacritty)
  128. (color (if dark-theme "dark" "light"))
  129. (font nil)
  130. (title nil)
  131. (scrollbar nil))
  132. (run-shell-command
  133. (let ((terminal-name (string-downcase (symbol-name terminal))))
  134. (case terminal
  135. ((alacritty)
  136. (join `(,terminal-name
  137. ,@(if title (list "--title" title) '())
  138. "--command" ,command)))
  139. ((xterm)
  140. (xterm-command :color color :command command :font font :title title :scrollbar scrollbar))
  141. ((st)
  142. (join `(,terminal-name
  143. ,*st-font-flag* ,(if font font *st-font*)
  144. ,@(if title (list "-t" title) '())
  145. ,*st-exec-flag* ,command)))))))
  146. ;;;
  147. ;;; QTerminal
  148. ;;;
  149. (defcommand qterminal () ()
  150. (run-shell-command (join (list *fontconfig-file* "qterminal"))))