mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-10 23:51:56 +00:00
feat(bin): t, custom tmux session manager
- drops tms bindings from tmux config, wasn't using them - drops t alias for tail -f, clashed with t script
This commit is contained in:
@@ -79,8 +79,6 @@ alias zapds='find . -name ".DS_Store" -print -delete'
|
|||||||
alias zappyc="find . -type f -name '*.pyc' -ls -delete"
|
alias zappyc="find . -type f -name '*.pyc' -ls -delete"
|
||||||
# Run all zaps
|
# Run all zaps
|
||||||
alias zapall="zapds && zappyc"
|
alias zapall="zapds && zappyc"
|
||||||
# tail with follow flag on
|
|
||||||
alias t='tail -f'
|
|
||||||
# directory usage, return only the total
|
# directory usage, return only the total
|
||||||
alias dn='du -chd1'
|
alias dn='du -chd1'
|
||||||
# Mirror site with wget
|
# Mirror site with wget
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
# ╭──────────────────────────────────────────────────────────╮
|
# ╭──────────────────────────────────────────────────────────╮
|
||||||
# │ Bindings │
|
# │ Bindings │
|
||||||
# ╰──────────────────────────────────────────────────────────╯
|
# ╰──────────────────────────────────────────────────────────╯
|
||||||
|
# bind flags
|
||||||
|
# -r = repeatable, only needs prefix once
|
||||||
|
# -n = doesn't need prefix
|
||||||
|
# -t = binds to a certain key-table (root, copy-mode, prefix, etc.)
|
||||||
|
|
||||||
# Set <prefix> to Control + Space, keeping the default of C-b intact.
|
# Set <prefix> to Control + Space, keeping the default of C-b intact.
|
||||||
# unbind C-b
|
# unbind C-b
|
||||||
@@ -39,11 +43,6 @@ bind r source-file ~/.dotfiles/config/tmux/tmux.conf \; display "tmux cfg reload
|
|||||||
bind -r '(' switch-client -p\; refresh-client -S
|
bind -r '(' switch-client -p\; refresh-client -S
|
||||||
bind -r ')' switch-client -n\; refresh-client -S
|
bind -r ')' switch-client -n\; refresh-client -S
|
||||||
|
|
||||||
# tms, https://github.com/jrmoulton/tmux-sessionizer
|
|
||||||
bind C-h display-popup -E "tms"
|
|
||||||
bind C-j display-popup -E "tms switch"
|
|
||||||
bind C-k display-popup -E "tms windows"
|
|
||||||
|
|
||||||
# Open a new window with <prefix> + N
|
# Open a new window with <prefix> + N
|
||||||
bind N new-window
|
bind N new-window
|
||||||
|
|
||||||
@@ -61,6 +60,10 @@ bind '"' split-window -v -c "#{pane_current_path}"
|
|||||||
bind '!' split-window -h -c "#{pane_current_path}"
|
bind '!' split-window -h -c "#{pane_current_path}"
|
||||||
bind '^' switch-client -t'{marked}'
|
bind '^' switch-client -t'{marked}'
|
||||||
|
|
||||||
|
# .local/bin/t triggers
|
||||||
|
bind -r T new-window ~/.local/bin/t
|
||||||
|
bind -r D run-shell "t ~/Code/ivuorinen/dotfiles"
|
||||||
|
|
||||||
# synchronize all panes in a window
|
# synchronize all panes in a window
|
||||||
bind y setw synchronize-panes
|
bind y setw synchronize-panes
|
||||||
|
|
||||||
|
|||||||
45
local/bin/t
Executable file
45
local/bin/t
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Credit to ThePrimeagen, jessarcher
|
||||||
|
# https://github.com/jessarcher/dotfiles/blob/master/scripts/t
|
||||||
|
#
|
||||||
|
# Tweaks by Ismo Vuorinen <https://github.com/ivuorinen> 2025
|
||||||
|
|
||||||
|
# Set environment variables for configuration with defaults
|
||||||
|
T_ROOT="${T_ROOT:-$HOME/Code}"
|
||||||
|
DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
|
||||||
|
|
||||||
|
# Function to print an error message and exit
|
||||||
|
error_exit()
|
||||||
|
{
|
||||||
|
echo "Error: $1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Select the directory
|
||||||
|
if [[ $# -eq 1 ]]; then
|
||||||
|
selected="$1"
|
||||||
|
else
|
||||||
|
items=$(find "$T_ROOT" -maxdepth 2 -mindepth 1 -type d)
|
||||||
|
items+="$(printf "\n%s" "$DOTFILES")"
|
||||||
|
items+="$(printf "\n/tmp")"
|
||||||
|
selected=$(echo -e "$items" | fzf) || exit 0 # Exit if no selection is made
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Exit if no directory was selected
|
||||||
|
[[ -z $selected ]] && error_exit "No directory selected."
|
||||||
|
|
||||||
|
# Sanitize the session name
|
||||||
|
dirname=$(basename "$selected" | tr '.' '_')
|
||||||
|
|
||||||
|
# Try to switch to the tmux session
|
||||||
|
if tmux switch-client -t "=$dirname" 2> /dev/null; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create a new tmux session or attach to an existing one
|
||||||
|
if tmux new-session -c "$selected" -d -s "$dirname" 2> /dev/null; then
|
||||||
|
tmux switch-client -t "$dirname"
|
||||||
|
else
|
||||||
|
tmux new -c "$selected" -A -s "$dirname"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user