<commit_before>":"; exec gosh -- $0 "$@"
;; -*- coding: utf-8 -*-

(define-module pikkukivi.commands.tmux-start
  (export tmux-start)
  (use gauche.process)
  (use gauche.parseopt)
  (use util.match)
  (use srfi-98))
(select-module pikkukivi.commands.tmux-start)


(define (new-session session window-name . command)
  (when (not (has-session? session))
    (run-process `(tmux -u2 new-session -d -s ,session -n ,window-name ,@command) :wait #t)))

(define (new-window session window-name . command)
  (run-process `(tmux -u2 new-window
                      -d
                      -n ,window-name ,@command) :wait #t))

(define (attach-session session)
  (run-process `(tmux -u2 attach-session -t ,session) :wait #t))

(define  (has-session? session)
  (let* ((p (run-process `(tmux -u2 -q has-session -t ,session) :wait #t :output :null :error :null))
         (status (process-exit-status p)))
    (if (zero? status)
      #t
      #f)))

(define (tmux)
  (cond
    ; inside tmux
    ((sys-getenv "TMUX")
     (print "[38;5;1myou're inside of tmux[0m"))
    (else
      (let ((main-session   "main")
            (second-session "daemon")
            (third-session  "servers")
            (shell (sys-getenv "SHELL")))
        (cond
          ; session exists
          ((has-session? main-session)
           (attach-session main-session))
          ; session not exists
          (else
            ;; create main session
            (new-session main-session "main")
            (new-window main-session  "vim" "vim")
            (new-window main-session  "w3m" "w3m google.com")

            ;; create second session
            (new-session second-session "futaba" )
            (new-window  second-session  "4ch" shell)
            (new-window  second-session  "danbooru" shell)
            (new-window  second-session  "konachan" shell)
            (new-window  second-session  "rtorrent" shell)
            ; (new-window  second-session "rtorrent" "rtorrent")

            ;; create third session
            (new-session third-session "servers")
            (new-window  third-session  "2ch" "ssh <EMAIL>")

            ; attach main session
            (attach-session main-session)))))))

(define (tmux-start args)
  (tmux))<commit_msg>tmux-start: add mpd<commit_after>":"; exec gosh -- $0 "$@"
;; -*- coding: utf-8 -*-

(define-module pikkukivi.commands.tmux-start
  (export tmux-start)
  (use gauche.process)
  (use gauche.parseopt)
  (use util.match)
  (use file.util)
  (use srfi-98))
(select-module pikkukivi.commands.tmux-start)


(define (new-session session window-name . command)
  (when (not (has-session? session))
    (run-process `(tmux -u2 new-session -d -s ,session -n ,window-name ,@command) :wait #t)))

(define (new-window session window-name . command)
  (run-process `(tmux -u2 new-window
                      -d
                      -n ,window-name ,@command) :wait #t))

(define (attach-session session)
  (run-process `(tmux -u2 attach-session -t ,session) :wait #t))

(define  (has-session? session)
  (let* ((p (run-process `(tmux -u2 -q has-session -t ,session) :wait #t :output :null :error :null))
         (status (process-exit-status p)))
    (if (zero? status)
      #t
      #f)))

(define (process-running? name)
  (if (equal? "" (process-output->string (string-append "pgrep " name) :on-abnormal-exit :ignore))
    #f #t))

(define (ncmpcpp session)
  (cond
    ((and (find-file-in-paths "musicpd")
       (find-file-in-paths "ncmpcpp"))
     (if (not (process-running? "musicpd"))
       (new-window session "ncmpcpp" "musicpd && ncmpcpp")
       (new-window session "ncmpcpp" "ncmpcpp")))))

(define (tmux)
  (cond
    ; inside tmux
    ((sys-getenv "TMUX")
     (print "[38;5;1myou're inside of tmux[0m"))
    (else
      (let ((main-session   "main")
            (second-session "daemon")
            (third-session  "servers")
            (shell (sys-getenv "SHELL")))
        (cond
          ; session exists
          ((has-session? main-session)
           (attach-session main-session))
          ; session not exists
          (else
            ;; create main session
            (new-session main-session "main")
            (new-window main-session  "vim" "vim")
            (new-window main-session  "w3m" "w3m google.com")
            (ncmpcpp main-session)

            ;; create second session
            (new-session second-session "futaba" )
            (new-window  second-session  "4ch" shell)
            (new-window  second-session  "danbooru" shell)
            (new-window  second-session  "konachan" shell)
            (new-window  second-session  "rtorrent" shell)
            ; (new-window  second-session "rtorrent" "rtorrent")

            ;; create third session
            (new-session third-session "servers")
            (new-window  third-session  "2ch" "ssh <EMAIL>")

            ; attach main session
            (attach-session main-session)))))))

(define (tmux-start args)
  (tmux))
{'fraction_non_alphanumeric': 0.1512351877887126, 'fraction_numerical': 0.006828680457923278, 'mean_word_length': 2.182108626198083, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6422865', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1641, 'n_words': 416}