From a9ec40568f328a39f63f0959b21ac013255b1848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gremaud?= Date: Fri, 5 May 2023 10:23:40 +0200 Subject: [PATCH] Add Tmux-sessionizer, tmux-cht, tmux conf and alias for nvim --- scripts/tmux-cht.sh | 14 ++++++++++++++ scripts/tmux-sessionizer | 26 ++++++++++++++++++++++++++ tmux.conf | 7 ++++++- zsh/alias.sh | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 scripts/tmux-cht.sh create mode 100755 scripts/tmux-sessionizer diff --git a/scripts/tmux-cht.sh b/scripts/tmux-cht.sh new file mode 100755 index 0000000..d639c24 --- /dev/null +++ b/scripts/tmux-cht.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +selected=`cat ~/.tmux-cht-languages ~/.tmux-cht-command | fzf` +if [[ -z $selected ]]; then + exit 0 +fi + +read -p "Enter Query: " query + +if grep -qs "$selected" ~/.tmux-cht-languages; then + query=`echo $query | tr ' ' '+'` + tmux neww bash -c "echo \"curl cht.sh/$selected/$query/\" & curl cht.sh/$selected/$query & while [ : ]; do sleep 1; done" +else + tmux neww bash -c "curl -s cht.sh/$selected~$query | less" +fi diff --git a/scripts/tmux-sessionizer b/scripts/tmux-sessionizer new file mode 100755 index 0000000..ddbaf6c --- /dev/null +++ b/scripts/tmux-sessionizer @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +if [[ $# -eq 1 ]]; then + selected=$1 +else + selected=$(find ~/Documents/Arcanite/ ~/Documents/PolyLAN/ ~/Documents/ -mindepth 1 -maxdepth 1 -type d | fzf) +fi + +if [[ -z $selected ]]; then + exit 0 +fi + +selected_name=$(basename "$selected" | tr . _) +tmux_running=$(pgrep tmux) + +if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then + tmux new-session -s $selected_name -c $selected + exit 0 +fi + +if ! tmux has-session -t=$selected_name 2> /dev/null; then + tmux new-session -ds $selected_name -c $selected +fi + +tmux switch-client -t $selected_name + diff --git a/tmux.conf b/tmux.conf index b6b95d8..61995b8 100644 --- a/tmux.conf +++ b/tmux.conf @@ -19,7 +19,9 @@ bind -n M-d select-pane -R # reload conf bind r source-file ~/.tmux.conf -setw -g mode-keys vi +set-window-option -g mode-keys vi +bind -T copy-mode-vi v send-keys -X begin-selection +bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' # change color #set -g pane-border-style 'fg=#660033' @@ -54,3 +56,6 @@ run -b '~/.tmux/plugins/tpm/tpm' set -s escape-time 0 set-option -g default-terminal "screen-256color" + +bind-key -r f run-shell "tmux neww ~/Documents/dotfiles/scripts/tmux-sessionizer" +bind-key -r i run-shell "tmux neww tmux-cht.sh" diff --git a/zsh/alias.sh b/zsh/alias.sh index 9510a60..117a50b 100644 --- a/zsh/alias.sh +++ b/zsh/alias.sh @@ -12,6 +12,7 @@ alias mg='python manage.py migrate' alias gp='git push' alias ga!='git commit --amend --no-edit --date now' +alias n='cd . && nvim -S' alias v='nvim' alias vi='nvim' alias vim='nvim'