From 12825d5147f5c0b1636dbda5ba34790d7c7bb236 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Fri, 9 Jun 2017 08:03:15 -0600 Subject: Moving files, cleaning up bug with drawer close (closing drawer in 2 places) --- Makefile | 2 +- README.md | 14 ++++--------- check_os.sh | 7 ------- color_palette.sh | 14 ------------- linux.tmux.config | 3 --- powerline.sh | 17 ---------------- scripts/check_os.sh | 34 ++++++++++++++++++++++++++++++++ scripts/color_palette.sh | 14 +++++++++++++ scripts/powerline.sh | 17 ++++++++++++++++ scripts/tmux_open_filename_in_vim.sh | 38 ++++++------------------------------ templates/template.yaml | 7 +++---- tmux.config | 6 +++--- 12 files changed, 82 insertions(+), 91 deletions(-) delete mode 100755 check_os.sh delete mode 100755 color_palette.sh delete mode 100755 linux.tmux.config delete mode 100755 powerline.sh create mode 100755 scripts/check_os.sh create mode 100755 scripts/color_palette.sh create mode 100755 scripts/powerline.sh diff --git a/Makefile b/Makefile index 4a52e48..bbb6608 100644 --- a/Makefile +++ b/Makefile @@ -4,5 +4,5 @@ help: install: ## Install the symlink ln -s $(CURDIR)/tmux.config ~/.tmux.conf -uninstall: ## Remove the sumlink +uninstall: ## Remove the symlink [[ -L ~/.muttrc ]] && rm ~/.tmux.conf diff --git a/README.md b/README.md index d8df7d7..675ca19 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,10 @@ # Setup -These are the settings that I use for tmux. -I use the code from tmux-powerline to get some cool functionality out of the status line. -I also added a few scripts in the scripts dir. -One is for listing active sessions/giving you the ability to call tmuxomatic scripts and the other script is for tmux renumbering. -All you need to do is pull this directory and symlink the tmux config to ~/.tmux.conf -I also use reattach-to-user-namespace to fix some copy/pastying stuff. -If you don't want it you can remove it from the config file. +These are the settings that I use for tmux. I used the code from the now +deprecated tmux-powerline to get some cool functionality out of the status line. ``` brew install reattach-to-user-namespace git clone https://github.com/thornycrackers/.tmux.git -ln -s .tmux/tmux.config .tmux.conf +make install ``` - -This will overwrite an existing .tmux.conf file if you have one. +The makefile will create the symlink of .tmux.conf diff --git a/check_os.sh b/check_os.sh deleted file mode 100755 index efee8b0..0000000 --- a/check_os.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -if [ "$(uname)" == "Darwin" ]; then - tmux source-file "$HOME/.tmux/mac.tmux.config" -elif [ "$(uname)" == "Linux" ]; then - tmux source-file "$HOME/.tmux/linux.tmux.config" -fi diff --git a/color_palette.sh b/color_palette.sh deleted file mode 100755 index 3762fae..0000000 --- a/color_palette.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Print tmux color palette. -# Idea from http://superuser.com/questions/285381/how-does-the-tmux-color-palette-work - -for i in $(seq 0 4 255); do - for j in $(seq $i $(expr $i + 3)); do - for k in $(seq 1 $(expr 3 - ${#j})); do - printf " " - done - printf "\x1b[38;5;${j}mcolour${j}" - [[ $(expr $j % 4) != 3 ]] && printf " " - done - printf "\n" -done diff --git a/linux.tmux.config b/linux.tmux.config deleted file mode 100755 index 091b4f0..0000000 --- a/linux.tmux.config +++ /dev/null @@ -1,3 +0,0 @@ -# vim: syntax=conf - -bind -Tcopy-mode-vi y send -X copy-pipe-and-cancel "tmux save-buffer - | xp" diff --git a/powerline.sh b/powerline.sh deleted file mode 100755 index 8baf3f2..0000000 --- a/powerline.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -RS="" -LS="" - -if [[ "$1" == "left" ]]; then - echo -n "#[fg=colour235, bg=colour142] $(tmux display-message -p '#S') #[fg=colour142, bg=colour241]$LS#[default]" - echo -n "#[fg=colour223, bg=colour241] $(hostname) #[fg=colour241, bg=colour235]$LS#[default]" -fi - -if [[ "$1" == "right" ]]; then - IP_ADDRESS=$(ip addr show | grep "inet[^6]" | grep -v "\(127.0.0.1\|docker\)" | tr -s ' ' | cut -d ' ' -f3 | cut -d '/' -f1) - echo -n "#[fg=colour235, bg=colour241]$RS#[fg=colour223, bg=colour241] ⓛ $IP_ADDRESS" - WAN_IP=$(curl --max-time 2 -s http://whatismyip.akamai.com/) - echo -n " ⓦ $WAN_IP #[default]" - DATE=$(date +"%b %d, %H:%M") - echo -n "#[fg=colour241, bg=colour142]$RS#[fg=colour235] $DATE #[default]" -fi diff --git a/scripts/check_os.sh b/scripts/check_os.sh new file mode 100755 index 0000000..e4abf85 --- /dev/null +++ b/scripts/check_os.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# vim: set filetype=sh : +# +# Author: Cody Hiar +# Date: 2017-06-09 +# +# Description:: Check the operatig system of the host and load the os specific +# options +# +# Set options: +# e: Stop script if command fails +# u: Stop script if unset variable is referenced +# x: Debug, print commands as they are executed +# o pipeline: If any command in a pipeline fails it all fails +# +set -euo pipefail + +# Main loop of program +main() { + if [ "$(uname)" == "Darwin" ]; then + # Setup 'v' to begin selection as in Vim + bind -T copy-mode-vi y send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy" + # Update default binding of `Enter` to also use copy-pipe + unbind -T copy-mode-vi Enter + bind-key -T copy-mode-vi Enter copy-pipe "reattach-to-user-namespace pbcopy" + # Allow pbcopy inside of session + set-option -g default-command "reattach-to-user-namespace -l zsh" + elif [ "$(uname)" == "Linux" ]; then + bind -Tcopy-mode-vi y send -X copy-pipe-and-cancel "tmux save-buffer - | xp" + tmux source-file "$HOME/.tmux/linux.tmux.config" + fi +} +main + diff --git a/scripts/color_palette.sh b/scripts/color_palette.sh new file mode 100755 index 0000000..3762fae --- /dev/null +++ b/scripts/color_palette.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Print tmux color palette. +# Idea from http://superuser.com/questions/285381/how-does-the-tmux-color-palette-work + +for i in $(seq 0 4 255); do + for j in $(seq $i $(expr $i + 3)); do + for k in $(seq 1 $(expr 3 - ${#j})); do + printf " " + done + printf "\x1b[38;5;${j}mcolour${j}" + [[ $(expr $j % 4) != 3 ]] && printf " " + done + printf "\n" +done diff --git a/scripts/powerline.sh b/scripts/powerline.sh new file mode 100755 index 0000000..8baf3f2 --- /dev/null +++ b/scripts/powerline.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +RS="" +LS="" + +if [[ "$1" == "left" ]]; then + echo -n "#[fg=colour235, bg=colour142] $(tmux display-message -p '#S') #[fg=colour142, bg=colour241]$LS#[default]" + echo -n "#[fg=colour223, bg=colour241] $(hostname) #[fg=colour241, bg=colour235]$LS#[default]" +fi + +if [[ "$1" == "right" ]]; then + IP_ADDRESS=$(ip addr show | grep "inet[^6]" | grep -v "\(127.0.0.1\|docker\)" | tr -s ' ' | cut -d ' ' -f3 | cut -d '/' -f1) + echo -n "#[fg=colour235, bg=colour241]$RS#[fg=colour223, bg=colour241] ⓛ $IP_ADDRESS" + WAN_IP=$(curl --max-time 2 -s http://whatismyip.akamai.com/) + echo -n " ⓦ $WAN_IP #[default]" + DATE=$(date +"%b %d, %H:%M") + echo -n "#[fg=colour241, bg=colour142]$RS#[fg=colour235] $DATE #[default]" +fi diff --git a/scripts/tmux_open_filename_in_vim.sh b/scripts/tmux_open_filename_in_vim.sh index b82c867..55f0c48 100755 --- a/scripts/tmux_open_filename_in_vim.sh +++ b/scripts/tmux_open_filename_in_vim.sh @@ -17,48 +17,22 @@ # Immutable globals readonly ARGS=( "$@" ) readonly PROGNAME=$(basename "$0") -readonly USAGE=$(cat << EOF -usage: $PROGNAME file_name - -Script that will search for a tmux pane running vim and will tell vim to open a -file specified by the passed in arguement - -OPTIONS: - -h Display help options -EOF -) - -# Function for processing arguments -cmdline() { - while getopts "h" FLAG; do - case "$FLAG" in - h) - echo "$USAGE" - exit 0 - ;; - *) - exit 0 - ;; - esac - done -} # Main loop of program main() { if [[ -z ${ARGS[0]} ]]; then exit fi - cmdline "${ARGS[@]}" - panes=($(tmux list-panes| awk -F: '{ print $1 }')) - for pane in "${panes[@]}"; do - pane_tty=$(tmux display -p -t "$pane" '#{pane_tty}') - ps -o state= -o comm= -t "$pane_tty" \ + CURRENT_PANE=$(tmux display-message -p "#{pane_index}") + PANES=($(tmux list-panes| awk -F: '{ print $1 }')) + for pane in "${PANES[@]}"; do + PANE_TTY=$(tmux display -p -t "$pane" '#{pane_tty}') + ps -o state= -o comm= -t "$PANE_TTY" \ | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$' &> /dev/null if [[ "$?" == 0 ]]; then filename="${ARGS[0]}" tmux send-keys -t "$pane" ":e $filename" Enter - tmux kill-pane - # tmux select-pane -t "$pane" + tmux select-pane -t "$pane" fi done } diff --git a/templates/template.yaml b/templates/template.yaml index 3218321..44a1c44 100644 --- a/templates/template.yaml +++ b/templates/template.yaml @@ -1,6 +1,5 @@ session_name: "${PROJECT}" start_directory: "${DIR}" -shell_command_before: make up windows: - window_name: code layout: even-vertical @@ -12,6 +11,6 @@ windows: - window_name: docker layout: even-vertical panes: - - make enter - - make enter - - make enter + - pane + - pane + - pane diff --git a/tmux.config b/tmux.config index 94dc931..ff910f0 100644 --- a/tmux.config +++ b/tmux.config @@ -75,11 +75,11 @@ set-option -g status-interval 2 set-option -g status-justify "centre" set-option -g status-left-length 110 set-option -g status-right-length 80 -set-option -g status-left "#(~/.tmux/powerline.sh left)" -set-option -g status-right "#(~/.tmux/powerline.sh right)" +set-option -g status-left "#(~/.tmux/scripts/powerline.sh left)" +set-option -g status-right "#(~/.tmux/scripts/powerline.sh right)" # Load/Ignore Mac specific options -run-shell "bash ~/.tmux/check_os.sh" +# run-shell "bash ~/.tmux/sripts/check_os.sh" # List of plugins set -g @plugin 'tmux-plugins/tpm' -- cgit v1.2.3