From 12825d5147f5c0b1636dbda5ba34790d7c7bb236 Mon Sep 17 00:00:00 2001
From: Cody Hiar <codyfh@gmail.com>
Date: Fri, 9 Jun 2017 08:03:15 -0600
Subject: Moving files, cleaning up bug with drawer close (closing drawer in 2
 places)

---
 scripts/check_os.sh                  | 34 ++++++++++++++++++++++++++++++++
 scripts/color_palette.sh             | 14 +++++++++++++
 scripts/powerline.sh                 | 17 ++++++++++++++++
 scripts/tmux_open_filename_in_vim.sh | 38 ++++++------------------------------
 4 files changed, 71 insertions(+), 32 deletions(-)
 create mode 100755 scripts/check_os.sh
 create mode 100755 scripts/color_palette.sh
 create mode 100755 scripts/powerline.sh

(limited to 'scripts')

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
 }
-- 
cgit v1.2.3