Skip to content

Commit

Permalink
feat(tmux): add popup session for vimwiki
Browse files Browse the repository at this point in the history
changes:
    + moved tmux config to .config/tmux
    + add bash script to open a tmux session
      in popup.
  • Loading branch information
PrashanthaTP committed Oct 24, 2021
1 parent 30a44fe commit b2eaf49
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .config/tmux/scripts/wiki.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

# Script to open Vimwiki dir in tmux popup

# exit if tmux not running
# -z checks if len of string is zero
# $TMX variable is automatically set if tmux server is running
[ -z "$TMUX" ] && exit 1

SESSION="wiki"

if [ "$(tmux display-message -p -F "#{session_name}")" = "${SESSION}" ];then
echo "Detaching from ${SESSION}"
tmux detach-client # detach if already in the popup
tmux display-message "detached from session:${SESSION}"
exit 1
fi

WINDOW="vimwiki"
SESSION_EXISTS=0

WIKI_INDEX_FILE="/d/dotfiles/wiki/vimwiki/index.md"

open_wiki(){
echo "Creating wiki session..."
# create a session if doesn't exist in a detached state
tmux new-session -d -s "${SESSION}" \;\
rename-window -t "${SESSION}:0" "${WINDOW}" \;\
split-window -t "${SESSION}:${WINDOW}.0" -h \;\
send-keys -t ${SESSION}:${WINDOW}.0 "vi ${WIKI_INDEX_FILE}" ENTER \;\
send-keys -t ${SESSION}:${WINDOW}.1 "cd \$(dirname ${WIKI_INDEX_FILE});clear" ENTER \;\
select-pane -t "${SESSION}:${WINDOW}.0" \;
}

tmux has-session -t "${SESSION}" &> /dev/null
[ $? == 0 ] && SESSION_EXISTS=1
[ ${SESSION_EXISTS} == 0 ] && open_wiki
echo "Attaching to session 'wiki'"
tmux display-message "Attaching to session:${SESSION}"
tmux display-popup -E -h "80%" -w "80%" "tmux attach -t ${SESSION}"

#tmux display-popup -E -h "80%" -w "80%" "tmux new-session -A -s ${SESSION} \;\
#rename-window -t 0 \"${WINDOW}\" \;\
#split-window -h \;\
#select-pane -t 0 \;\
#send-keys -t ${SESSION}.0 \"${VI_CMD}\" ENTER"

118 changes: 118 additions & 0 deletions .config/tmux/tmux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
set -s default-terminal 'xterm-256color'

######################
# Custom scripts
######################
bind-key N run-shell -b "bash ~/.config/tmux/scripts/wiki.sh"

# credits : https://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/
######################
# Prefix
######################
unbind C-b
set-option -g prefix C-a

######################
# Splits
######################
unbind '"'
unbind '%'

bind | split-window -h
bind - split-window -v

bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

unbind-key l
# by default used for last used window
bind h select-pane -L
bind l select-pane -R
bind k select-pane -U
bind j select-pane -D


######################
# Source config
######################

bind R source-file ~/.config/tmux/tmux.conf \; display-message "Reloading tmux config"

######################
# Mouse control
######################
# > tmux 2.1
set -g mouse on
#set -g mouse-select-window on
#set -g mouse-select-pane on
#set -g mouse-resize-pane on

######################
# Windows
######################
set-option -g allow-rename off
set-window-option -g mode-keys vi
bind L last-window
######################
# Copy-Paste Mode
######################
# use v to trigger selection
bind-key -T copy-mode-vi v send-keys -X begin-selection

# use y to yank current selection
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'tee /dev/clipboard'

bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
######################
# Synchronize Panes
######################
bind-key S set-window-option synchronize-panes \; display-message "Synchronize-panes #{?pane_synchronized,on,off}"

######################
# Visual aspects
######################

# loud or quiet?
set -g visual-activity off
set -g visual-bell off
set -g visual-silence off
setw -g monitor-activity off
set -g bell-action none

# modes
setw -g clock-mode-colour colour5
setw -g mode-style 'fg=colour1 bg=colour18 bold'

# panes
set -g pane-border-style 'fg=colour19 bg=colour0'
set -g pane-active-border-style 'bg=colour0 fg=colour9'

######################
# statusbar
# status-left window-list status-right
######################

set -g status-position bottom
set -g status-justify left
set -g status-style 'bg=colour235 fg=colour223 dim'
set -g status-left '#{?client_prefix,#[bg=colour100],}#{?client_prefix,#[fg=colour0],} ❐ #S #{?window_zoomed_flag,🔍,} '
#set -g status-right '#[fg=colour253,bg=colour233] %d/%m #[fg=colour233,bg=colour8] %H:%M:%S '
set -g status-right '#{?pane_synchronized, * ,}'
set -g status-right-length 50
set -g status-left-length 20

setw -g window-status-current-style 'fg=colour235 bg=colour172'
#setw -g window-status-current-format ' #I#[fg=colour249]:#[fg=colour255]#W#[fg=colour249]#F '
setw -g window-status-current-format ' #I:#[bold]#W#[default]#F '

setw -g window-status-style 'fg=colour223 bg=colour237'
#setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '
setw -g window-status-format ' #I:#W#F '


#setw -g window-status-bell-style 'fg=colour255 bg=colour1 bold'

# messages
set -g message-style 'fg=colour254 bg=colour16 bold'

0 comments on commit b2eaf49

Please sign in to comment.