0
0
Просмотр исходного кода

feat(tmux): add Alacritty / `tmux` management scripts

Joe 1 год назад
Родитель
Сommit
8d03818a82

+ 2 - 0
.config/alacritty/alacritty.toml

@@ -4,6 +4,7 @@
 # Docs:
 # * https://alacritty.org/config-alacritty.html
 #
+# Configured for MacOS, tmux, and Neovim.
 ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
 
 # https://github.com/alacritty/alacritty/blob/master/extra/man/alacritty.5.scd
@@ -18,6 +19,7 @@ import = [
 TERM = "alacritty"
 [shell]
 program = "/bin/zsh"
+args = ["--login", "-c", "~/.scripts/terminal_launch.zsh"]
 
 [window]
 decorations = "none"

+ 5 - 0
.config/tmux/tmux.conf

@@ -5,6 +5,11 @@
 #
 # === === === === === === === === === === === === === === === === === === ===
 
+# Disable the leader key
+unbind C-b
+# Instead, use the omnibar script for controlling tmux
+bind -n C-S-Space run-shell -b "/bin/zsh ~/.scripts/omnibar.zsh"
+
 # Default commands
 set-option -g default-shell /bin/zsh
 

+ 4 - 0
.github/README.md

@@ -55,6 +55,10 @@ terminal UI for git commands.
 
 Configuration for [Prettier](http://prettier.io), an opinionated code formatter.
 
+### [scripts (`~/.scripts/`)](./.scripts/)
+
+Standalone shell scripts to be called by other programs.
+
 ### [tmux (`~/.config/tmux/`)](./.config/tmux/)
 
 Configuration for [tmux](https://github.com/tmux/tmux), a terminal multiplexer.

+ 12 - 0
.scripts/nvim_launch.zsh

@@ -0,0 +1,12 @@
+#!/bin/zsh
+P=${1:-$( HOME )}
+tmux rename-window $(basename $P);
+cd $P
+while true; do;
+    if [ -f ./.venv/bin/activate ]; then
+        source ./.venv/bin/activate
+    elif [ -f ./venv/bin/activate ]; then
+        source ./venv/bin/activate
+    fi
+    nvim;
+done;

+ 29 - 0
.scripts/omnibar.zsh

@@ -0,0 +1,29 @@
+#!/bin/zsh
+tmux display-menu -t . \
+    -T "tmux omnibar" \
+    "Command Prompt" "a" "command-prompt" \
+    "Command List" "r" "list-commands" \
+    "Select Pane" "s" "choose-tree" \
+    ""  \
+    "Open Project" "p" "new-window /bin/zsh ~/.scripts/project_launch.zsh" \
+    "Open Shell" "o" "new-window /bin/zsh" \
+    "Launch SSH" "v" "new-window /bin/zsh ~/.scripts/ssh_launch.zsh" \
+    ""  \
+    "Next Pane" "Right" "select-pane -t :.+" \
+    "Previous Pane" "Left" "select-pane -t :.-" \
+    "Recent Pane" "t" "select-pane -p" \
+    "Next Window" "Down" "select-window -n" \
+    "Previous Window" "Up" "select-window -p" \
+    "Recent Window" "n" "last-window" \
+    ""  \
+    "Vertical Split" "|" "split-window -h -c \"#{pane_current_path}\"" \
+    "Horizontal Split" "-" "split-window -v -c \"#{pane_current_path}\"" \
+    "Rotate Window" "y" "rotate-window -D" \
+    "Zoom Pane" "z" "resize-pane -Z" \
+    ""  \
+    "Screenshot" "+" "run-shell \"/bin/zsh -l ~/.scripts/tmux_screencap.zsh\"" \
+    ""  \
+    "New Window" "c" "new-window /bin/zsh ~/.scripts/nvim_launch.zsh" \
+    "Close Pane" "x" "kill-pane" \
+    "Close Window" "q" "split-window -v -c \"#{pane_current_path}\"" \
+    "Detach Session" "d" "detach"

+ 26 - 0
.scripts/open_application.zsh

@@ -0,0 +1,26 @@
+#!/bin/zsh
+TERMINAL_PATH=/Applications/Alacritty.app/
+BROWSER_PATH=/Applications/Chromium.app/
+FINDER_PATH=/System/Library/CoreServices/Finder.app/
+COMMUNICATIONS_PATH=/Applications/Slack.app/
+ALT_COMMUNICATIONS_PATH=/Applications/Signal.app/
+MUSIC_PATH=/Applications/Spotify.app/
+NOTETAKING_PATH=/Applications/Obsidian.app/
+VIDEOCALL_PATH=/Applications/Google\ Meet.app/
+
+case $1 in
+    terminal)
+        open $TERMINAL_PATH ;;
+    browser)
+        open $BROWSER_PATH ;;
+    finder)
+        (yabai -m query --windows | jq 'map(select(.app=="Finder")) | first | .id' | xargs -n1 yabai -m window $1 --focus) || open $FINDER_PATH ;;
+    communications)
+        open $COMMUNICATIONS_PATH || open $ALT_COMMUNICATIONS_PATH;;
+    music)
+        open $MUSIC_PATH ;;
+    notetaking)
+        open $NOTETAKING_PATH ;;
+    videocall)
+        open $VIDEOCALL_PATH ;;
+esac

+ 12 - 0
.scripts/project_launch.zsh

@@ -0,0 +1,12 @@
+#!/bin/zsh
+tmux new-window \
+    /bin/zsh ~/.scripts/nvim_launch.zsh \
+   $( \
+        fd \
+            --base-directory ~ \
+            -t d \
+            -d 5 \
+            -u -E '.[a-fh-zA-FG-Z]*' \
+            --prune \\.git$ \
+            -x echo {//} \
+    | fzf)

+ 12 - 0
.scripts/ssh_launch.zsh

@@ -0,0 +1,12 @@
+#!/bin/zsh
+LOCATIONS=$(grep -ioE "ssh [a-z0-9]+@[a-z0-9]+\.[a-z0-9]+" $ZDOTDIR/.zsh_history | cut -c 5- | uniq)
+if [[ $1 =~ '^[0-9]+$' ]] ; then
+    echo $(echo $LOCATIONS | tac | head -n $1)
+    exit
+fi
+if [[ -z "$1" ]]; then
+    LOCATION=$(echo $LOCATIONS | sort | uniq | fzf)
+else
+    LOCATION=$1
+fi
+ssh $LOCATION -t 'tmux new-session -A -s alpha'

+ 70 - 0
.scripts/terminal_launch.zsh

@@ -0,0 +1,70 @@
+#!/bin/zsh
+while true; do
+    tput civis;
+    items=("zsh" "alpha")
+    items+=("${(@f)$(tmux list-sessions -F '#S' | grep -v '^alpha$' | cat - <(echo 'beta\ngamma') | uniq | head -n 2)}")
+    items+=("${(z)$(~/.scripts/ssh_launch.zsh 2)}")
+    printf "\r\n"
+    printf "  Welcome to \e[31m${TERM}\e[0m, \e[33m${USER}\e[0m@\e[33m${HOST}\e[0m.\n"
+    printf "\n"
+    printf "  a) Open a \e[36mlocal\e[0m \e[4m${items[1]}\e[0m shell.\n"
+    printf "  r) \e[3m(Default)\e[0m Attach the \e[33m${items[2]}\e[0m \e[4mtmux\e[0m session.\n"
+    printf "  s) Attach the \e[33m${items[3]}\e[0m \e[4mtmux\e[0m session.\n"
+    printf "  t) Attach the \e[33m${items[4]}\e[0m \e[4mtmux\e[0m session.\n"
+    printf "  n) Start an \e[4mssh\e[0m session for \e[31m${items[5]}\e[0m.\n"
+    printf "  e) Start an \e[4mssh\e[0m session for \e[31m${items[6]}\e[0m.\n"
+    printf "  i) \e[33mSelect\e[0m a \e[4mtmux\e[0m session.\n"
+    printf "  o) \e[31mSelect\e[0m an \e[4mssh\e[0m session.\n"
+    printf "\n"
+    for countdown in 10 9 8 7 6 5 4 3 2 1; do
+        for dots in 0 1 2 3 4 5; do
+            if [[ -z "$selection" ]]; then
+                printf "\r  Defaulting to \e[4mtmux\e[0m \e[33m${items[2]}\e[0m in ${countdown}";
+                for dotprint in 0 1 2 3 4 5; do
+                    if (( $dots > dotprint )); then
+                        printf "."
+                    else
+                        printf " "
+                    fi;
+                done;
+                read -k1 -s -t 0.2 selection
+            fi
+        done;
+    done;
+    clear;
+    tput cnorm;
+    case $selection in
+        a)
+            /bin/zsh
+            ;;
+        r|"")
+            tmux new-session -A -s ${items[2]}
+            ;;
+        s)
+            tmux new-session -A -s ${items[3]}
+            ;;
+        t)
+            tmux new-session -A -s ${items[4]}
+            ;;
+        n)
+            /bin/zsh -c "~/.scripts/ssh_launch.zsh ${items[5]}"
+            ;;
+        e)
+            /bin/zsh -c "~/.scripts/ssh_launch.zsh ${items[6]}"
+            ;;
+        i)
+            # It's hard to know if we're is already in a tmux pane; but, if the
+            # `choose-tree` command fails instantly, then we're probably not!
+            starttime=$(date +%s);
+            tmux choose-tree;
+            if [ $starttime -eq $(date +%s) ]; then
+                tmux new-session -A -s ${items[2]}\; choose-tree;
+            fi
+            ;;
+        o)
+            /bin/zsh -c ~/.scripts/ssh_launch.zsh
+            ;;
+    esac;
+    selection=""
+    clear;
+done;

+ 19 - 0
.scripts/tmux_screencap.zsh

@@ -0,0 +1,19 @@
+#!/bin/zsh
+source $ZDOTDIR/.zshrc
+
+OUTPUT_DIRECTORY="$HOME/Pictures/tmux/Screenshot $(date +"%Y-%m-%d at %H.%M.%S")/"
+mkdir -p $OUTPUT_DIRECTORY
+cd $OUTPUT_DIRECTORY
+
+tmux capture-pane -pNJ > terminal.txt
+tmux capture-pane -peNJ > terminal.ansi
+screencapture -Jwindow -m -o terminal.png
+
+# ansisvg converts the capture to an svg
+# https://github.com/wader/ansisvg.git
+if command -v ansisvg &> /dev/null
+then
+    cat terminal.ansi | ansisvg > terminal.svg
+    cat terminal.ansi | ansisvg --grid --fontname "JetBrainsMonoNL NF" > terminal.embedded.svg
+fi
+