Browse Source

Add new script, tmux sessions helper

Vova Tkach 5 years ago
parent
commit
96f20df9cd
3 changed files with 50 additions and 0 deletions
  1. 4 0
      Makefile
  2. 1 0
      README.md
  3. 45 0
      sess

+ 4 - 0
Makefile

@@ -5,6 +5,7 @@ RELEASEURL_iptables_http_cloudflare:="https://github.com/vladimirok5959/bash-lin
 RELEASEURL_iptables_write:="https://github.com/vladimirok5959/bash-linux-utils/releases/download/latest/iptables-write"
 RELEASEURL_ping_disable:="https://github.com/vladimirok5959/bash-linux-utils/releases/download/latest/ping-disable"
 RELEASEURL_ping_enable:="https://github.com/vladimirok5959/bash-linux-utils/releases/download/latest/ping-enable"
+RELEASEURL_sess:="https://github.com/vladimirok5959/bash-linux-utils/releases/download/latest/sess"
 
 BINDIR:=/usr/local/bin
 
@@ -33,6 +34,9 @@ install:
 	@wget -q $(RELEASEURL_ping_enable) -O $(BINDIR)/ping-enable > /dev/null
 	@chmod 755 $(BINDIR)/ping-enable
 	@echo "[OK] $(BINDIR)/ping-enable"
+	@wget -q $(RELEASEURL_sess) -O $(BINDIR)/sess > /dev/null
+	@chmod 755 $(BINDIR)/sess
+	@echo "[OK] $(BINDIR)/sess"
 	@echo "All installed successfully"
 info:
 	@echo "You can run 'make install'"

+ 1 - 0
README.md

@@ -21,6 +21,7 @@ Downloading...
 [OK] /usr/local/bin/iptables-write
 [OK] /usr/local/bin/ping-disable
 [OK] /usr/local/bin/ping-enable
+[OK] /usr/local/bin/sess
 All installed successfully
 ```
 cd ~; rm -rd ~/tmplinutils

+ 45 - 0
sess

@@ -0,0 +1,45 @@
+#!/bin/bash
+
+###############################################################################
+# Add this to ~/.bashrc
+###############################################################################
+# Sess autocomplete
+# sess_completions()
+# {
+# 	if [ "${#COMP_WORDS[@]}" != "2" ]; then
+# 		return
+# 	fi
+
+# 	while read line; do
+# 		COMPREPLY+=("${line}")
+# 	done <<<$(sess autocomplete | grep "${COMP_WORDS[1]}")
+# }
+# complete -F sess_completions sess
+###############################################################################
+
+session_name="$1"
+session_name_new="$2"
+
+if [[ $session_name = "autocomplete" ]]; then
+	tmux ls | awk -F":" '{ print $1 }'
+	exit 0
+fi
+
+if [[ $session_name != "" ]]; then
+	if [[ $session_name_new != "" ]]; then
+		tmux rename-session -t $session_name $session_name_new
+		exit 0
+	fi
+fi
+
+if [[ $session_name == "" ]]; then
+	tmux ls
+else
+	tmux has-session -t $session_name 2>/dev/null
+	result="$?"
+	if [ $result == "0" ]; then
+		tmux attach -t $session_name
+	else
+		tmux new -s $session_name
+	fi
+fi