Remove scripts folder
This commit is contained in:
parent
9bda4605f9
commit
8a8f8eba14
9249
scripts/configparser
9249
scripts/configparser
File diff suppressed because it is too large
Load Diff
3743
scripts/inquirer
3743
scripts/inquirer
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
|||||||
#!/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
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# ssh-multi
|
|
||||||
# D.Kovalov
|
|
||||||
# Based on http://linuxpixies.blogspot.jp/2011/06/tmux-copy-mode-and-how-to-control.html
|
|
||||||
|
|
||||||
# a script to ssh multiple servers over multiple tmux panes
|
|
||||||
|
|
||||||
|
|
||||||
starttmux() {
|
|
||||||
if [ -z "$HOSTS" ]; then
|
|
||||||
echo -n "Please provide of list of hosts separated by spaces [ENTER]: "
|
|
||||||
read HOSTS
|
|
||||||
fi
|
|
||||||
|
|
||||||
local hosts=( $HOSTS )
|
|
||||||
local target="ssh-multi ${host[0]}"
|
|
||||||
|
|
||||||
tmux new-window -n "${target}" ssh ${hosts[0]}
|
|
||||||
unset hosts[0];
|
|
||||||
for i in "${hosts[@]}"; do
|
|
||||||
tmux split-window -t :"${target}" -h "ssh $i"
|
|
||||||
tmux select-layout -t :"${target}" tiled > /dev/null
|
|
||||||
done
|
|
||||||
tmux select-pane -t 0
|
|
||||||
tmux set-window-option -t :"${target}" synchronize-panes on > /dev/null
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
HOSTS=${HOSTS:=$*}
|
|
||||||
|
|
||||||
starttmux
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [[ $# -eq 1 ]]; then
|
|
||||||
selected=$1
|
|
||||||
else
|
|
||||||
selected=$(find ~/Documents/Arcanite/ ~/Documents/PolyLAN/ ~/Documents/Python ~/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
|
|
||||||
|
|
||||||
@ -1,110 +0,0 @@
|
|||||||
import configparser
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import libtmux
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
|
||||||
|
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config_path = Path("~/.ssh-tmux-multi.ini").expanduser()
|
|
||||||
config.read(config_path)
|
|
||||||
|
|
||||||
fav_key = "Favourite servers"
|
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_known_ssh_hosts():
|
|
||||||
servers = set()
|
|
||||||
|
|
||||||
# Check known hosts on ssh folder
|
|
||||||
with open(Path("~/.ssh/known_hosts").expanduser(), "r") as file:
|
|
||||||
lines = file.read().strip().split("\n")
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
servers.add(line.split(" ")[0])
|
|
||||||
|
|
||||||
# Check previous ssh command on histfile
|
|
||||||
with open(Path("~/.histfile").expanduser(), "r", encoding="utf-8", errors="ignore") as file:
|
|
||||||
lines = file.read().strip().split("\n")
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
if line[15:].startswith("ssh "):
|
|
||||||
server = line[19:].strip()
|
|
||||||
if server:
|
|
||||||
servers.add(server)
|
|
||||||
|
|
||||||
return sorted(list(servers), reverse=True)
|
|
||||||
|
|
||||||
|
|
||||||
def get_favourite_servers_first():
|
|
||||||
servers = get_all_known_ssh_hosts()
|
|
||||||
|
|
||||||
if fav_key not in config.sections():
|
|
||||||
return servers
|
|
||||||
|
|
||||||
order = {}
|
|
||||||
for server in servers:
|
|
||||||
order[server] = '0'
|
|
||||||
|
|
||||||
for server, uses in config[fav_key].items():
|
|
||||||
if server in order:
|
|
||||||
order[server] = uses
|
|
||||||
|
|
||||||
# Return the most used servers first
|
|
||||||
return [x[0] for x in sorted(order.items(), key=lambda x: int(x[1]), reverse=True)]
|
|
||||||
|
|
||||||
|
|
||||||
def write_choosen_servers(servers):
|
|
||||||
"""Write the servers usage in the config file."""
|
|
||||||
|
|
||||||
if fav_key not in config.sections():
|
|
||||||
config[fav_key] = {}
|
|
||||||
|
|
||||||
for server in servers:
|
|
||||||
if server in config[fav_key]:
|
|
||||||
config[fav_key][server] = str(int(config[fav_key][server]) + 1)
|
|
||||||
|
|
||||||
else:
|
|
||||||
config[fav_key][server] = '1'
|
|
||||||
|
|
||||||
with open(config_path, "w") as file:
|
|
||||||
config.write(file)
|
|
||||||
|
|
||||||
servers = fzf.prompt(get_favourite_servers_first(), "--cycle --multi --print-query")
|
|
||||||
|
|
||||||
# Strip from query if found else, use the query
|
|
||||||
if len(servers) > 1:
|
|
||||||
servers = servers[1:]
|
|
||||||
|
|
||||||
if not servers:
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
write_choosen_servers(servers)
|
|
||||||
|
|
||||||
srv = libtmux.Server()
|
|
||||||
active_session = srv.sessions.filter(session_attached='1')[0]
|
|
||||||
window = active_session.new_window(f"ssh-multis {','.join(servers)}", window_shell=f"ssh {servers[0]}")
|
|
||||||
|
|
||||||
for server in servers[1:]:
|
|
||||||
window.select_layout("tiled")
|
|
||||||
pane = window.split(shell=f"ssh {server}")
|
|
||||||
|
|
||||||
# Wait until tmux finished working
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
# Confirm connection on asking panes
|
|
||||||
confirmation_needed_text = "Are you sure you want to continue connecting (yes/no/[fingerprint])?"
|
|
||||||
for pane in window.panes:
|
|
||||||
pane_content = pane.capture_pane()
|
|
||||||
if pane_content and confirmation_needed_text == pane_content[-1]:
|
|
||||||
pane.send_keys("yes")
|
|
||||||
|
|
||||||
window.set_window_option("synchronize-panes", "on")
|
|
||||||
pane = window.panes[0]
|
|
||||||
pane.send_keys("sudo su -")
|
|
||||||
window.set_window_option("synchronize-panes", "off")
|
|
||||||
|
|
||||||
window.select()
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
import libtmux
|
|
||||||
import configparser
|
|
||||||
import time
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
|
||||||
|
|
||||||
|
|
||||||
BASE_PATH = Path("~/.ssh-tmux/").expanduser()
|
|
||||||
|
|
||||||
configs = {}
|
|
||||||
sections = {}
|
|
||||||
for subconffile in os.listdir(BASE_PATH):
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(BASE_PATH / subconffile)
|
|
||||||
|
|
||||||
configs[subconffile] = config
|
|
||||||
|
|
||||||
for section in config.sections():
|
|
||||||
sections[section] = subconffile
|
|
||||||
|
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
|
||||||
selected_group = fzf.prompt(sections.keys(), "--cycle")[0]
|
|
||||||
|
|
||||||
config = configs[sections[selected_group]]
|
|
||||||
|
|
||||||
servers = config[selected_group]["servers"].split("\n")
|
|
||||||
|
|
||||||
extra_commands = []
|
|
||||||
if "commands" in config[selected_group].keys():
|
|
||||||
extra_commands = config[selected_group]["commands"].split("\n")
|
|
||||||
|
|
||||||
if not servers:
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
srv = libtmux.Server()
|
|
||||||
active_sessions = srv.sessions.filter(session_attached='1')
|
|
||||||
|
|
||||||
if active_sessions:
|
|
||||||
active_session = active_sessions[0]
|
|
||||||
|
|
||||||
else:
|
|
||||||
raw_try = srv.cmd("display", "-p", "#{session_name}").stdout
|
|
||||||
if raw_try:
|
|
||||||
active_session = srv.sessions.filter(name=raw_try[0])[0]
|
|
||||||
|
|
||||||
else:
|
|
||||||
active_session = srv.sessions[0]
|
|
||||||
|
|
||||||
window = active_session.new_window(f"ssh-multig {','.join(servers)}", window_shell=f"ssh {servers[0]}")
|
|
||||||
|
|
||||||
for server in servers[1:]:
|
|
||||||
window.select_layout("tiled")
|
|
||||||
pane = window.split(shell=f"ssh {server}")
|
|
||||||
|
|
||||||
# Wait until tmux finished working
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
# Confirm connection on asking panes
|
|
||||||
confirmation_needed_text = "Are you sure you want to continue connecting (yes/no/[fingerprint])?"
|
|
||||||
for pane in window.panes:
|
|
||||||
pane_content = pane.capture_pane()
|
|
||||||
if pane_content and confirmation_needed_text == pane_content[-1]:
|
|
||||||
pane.send_keys("yes")
|
|
||||||
|
|
||||||
window.set_window_option("synchronize-panes", "on")
|
|
||||||
pane = window.panes[0]
|
|
||||||
pane.send_keys("sudo su -")
|
|
||||||
|
|
||||||
for command in extra_commands:
|
|
||||||
pane.send_keys(command)
|
|
||||||
|
|
||||||
window.set_window_option("synchronize-panes", "off")
|
|
||||||
|
|
||||||
window.select()
|
|
||||||
srv.cmd("select-layout", "tiled")
|
|
||||||
Loading…
Reference in New Issue
Block a user