From fc22288a508cfcae83b968112170bd22d1e26988 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Wed, 19 Jul 2023 23:21:29 -0500 Subject: [PATCH] Rename, delete --- charmssh | 42 ----------- check-reboot | 38 ---------- create-archive | 8 +++ dboxen | 10 --- dboxrm | 11 --- gumosh | 51 ------------- nerdfont-installer | 173 +++++++++++++++++++++++++++++++++++++++++++++ split-man | 21 ++++++ 8 files changed, 202 insertions(+), 152 deletions(-) delete mode 100755 charmssh delete mode 100755 check-reboot create mode 100755 create-archive delete mode 100755 dboxen delete mode 100755 dboxrm delete mode 100755 gumosh create mode 100755 nerdfont-installer create mode 100755 split-man diff --git a/charmssh b/charmssh deleted file mode 100755 index fb2c5de..0000000 --- a/charmssh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -# This script uses Charm's Skate and Gum tools to select SSH hosts and connect -# to them. - -# Check for gum and skate. -if ! test -x "$(command -v gum)"; then - echo "Missing dependency: gum" - echo "See github.com/charmbracelet/gum" - exit 1 -fi - -if ! test -x "$(command -v skate)"; then - echo "Missing dependency: skate" - echo "See github.com/charmbracelet/skate" - exit 1 -fi - -# Set CHARM_HOST -export CHARM_HOST="nexus.local" - -# Select SSH host key from skate store with gum, get value with skate. -KEY=$(skate list -k | gum choose --limit=1) -if test -z "$KEY"; then - exit 0 -fi - -VALUE=$(skate get "$KEY") - -# If VALUE contains non-standard SSH port, set PORT. -HOST=$(echo "$VALUE" | cut -d ":" -f 1) - -if [[ "$VALUE" == *":"* ]]; then - PORT=$(echo "$VALUE" | cut -d ":" -f 2) -fi - -# autossh into $HOST, using $PORT, if values are non-zero -if test -n "$PORT"; then - autossh -M 0 "$HOST" -p "$PORT" -X -else - autossh -M 0 "$HOST" -X -fi diff --git a/check-reboot b/check-reboot deleted file mode 100755 index 7aad58c..0000000 --- a/check-reboot +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -HOSTS_FILE="${HOME}/.server_hosts" -host_array=() -YELLOW='\033[1;33m' -GREEN='\033[1;32m' -NC='\033[0m' - -# Read hosts from ~/.server_hosts -while IFS= read -r line; do - host_array+=("$line") -done < "${HOSTS_FILE}" - -for host in "${host_array[@]}"; do - hostname=$(echo "$host" | cut --delimiter="@" --fields=2) - if ssh "$host" -- test -f /etc/redhat-release; then - if ssh "$host" -- sudo needs-restarting -r >/dev/null; then - echo -e "$hostname: ${GREEN}OK${NC}" - else - ssh "$host" -- sudo systemctl reboot >/dev/null - echo -e "$hostname: ${YELLOW}Reboot initiated${NC}" - notify-send "$hostname: Reboot initiated" - fi - elif ssh "$host" -- test -f /etc/debian_version; then - if ssh "$host" -- ! test -f /var/run/reboot-required; then - echo -e "$hostname: ${GREEN}OK${NC}" - else - ssh "$host" -- sudo systemctl reboot >/dev/null - echo -e "$hostname: ${YELLOW}Reboot initiated${NC}" - notify-send "$hostname: Reboot initiated" - fi - else - echo "$hostname is not a Debian/Ubuntu or RHEL-compatible system." - echo "Reboot check aborted" - fi -done diff --git a/create-archive b/create-archive new file mode 100755 index 0000000..5228e4e --- /dev/null +++ b/create-archive @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +# Create a tarball from given directory. + +archive_name="$1.tar.gz" +archive_name=${archive_name/\//} +tar cvfz "$archive_name" "$1" +echo "Created archive $archive_name" diff --git a/dboxen b/dboxen deleted file mode 100755 index 5ddabec..0000000 --- a/dboxen +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -if ! test -x "$(command -v gum)"; then - echo "Missing dependency: gum" - echo "See github.com/charmbracelet/gum" - exit 1 -fi - -distrobox enter \ - $(distrobox list | tail -n +2 | gum choose --limit=1 | awk '{ print $3 }') diff --git a/dboxrm b/dboxrm deleted file mode 100755 index abf88d4..0000000 --- a/dboxrm +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -if ! test -x "$(command -v gum)"; then - echo "Missing dependency: gum" - echo "See github.com/charmbracelet/gum" - exit 1 -fi - -for box in $(distrobox list | tail -n +2 | gum choose --no-limit | awk '{ print $3 }'); do - distrobox rm -f $box; -done diff --git a/gumosh b/gumosh deleted file mode 100755 index 2032bd3..0000000 --- a/gumosh +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash - -# This script parses the ssh config at ~/.ssh/config to find user@host -# entries, then uses gum choose to select one user@host to ssh into. - -# Check for gum. -if ! test -x "$(command -v gum)"; then - echo "Missing dependency: gum" - echo "See github.com/charmbracelet/gum" - exit 1 -fi - -SSH_CONFIG="${HOME}/.ssh/config" -usern_array=() -hostn_array=() -logins=() - -# Read Users from ssh config and store them in usern_array. -while IFS= read -r line; do - if [[ "$line" == *"User"* ]]; then - usern=$(echo $line | awk '{ print $2 }') - usern_array+=($usern) - fi -done < "${SSH_CONFIG}" - -# Read HostNames from ssh config and store them in hostn_array. -while IFS= read -r line; do - if [[ "$line" == *"HostName"* ]]; then - hostn=$(echo $line | awk '{ print $2 }') - hostn_array+=($hostn) - fi -done < "${SSH_CONFIG}" - -# Set the array_len to the size of usern_array - 1. -let "array_len = ${#usern_array[@]} - 1" - -# Iterate through usern_array and hostn_array and match user and host -# pairs, then store them in the logins array in "user@host" format. -for i in $(seq 0 $array_len); do - userhost=$(printf "%s@%s" "${usern_array[i]}" "${hostn_array[i]}") - logins+=($userhost) -done - -# Print each member of logins array on a new line and pipe to gum choose. -# Store selection. -selection=$(printf "%s\n" "${logins[@]}" | gum choose --limit=1) - -# If $selection is non-empty, pass it to the ssh -X command. -if test -n "${selection}"; then - mosh -p 60000 "${selection}" -fi diff --git a/nerdfont-installer b/nerdfont-installer new file mode 100755 index 0000000..85a2aa0 --- /dev/null +++ b/nerdfont-installer @@ -0,0 +1,173 @@ +#!/usr/bin/env bash + +# LICENSE +# Copyright 2022 Jeffrey Serio +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set -eu +set -o pipefail +set -o posix + +# Check for dependencies: curl and gum. +if ! test -x "$(command -v curl)"; then + echo "Missing dependencies: please install curl." + exit 1 +fi + +if ! test -x "$(command -v gum)"; then + echo "Missing dependencies: please install the gum command." + echo "See https://github.com/charmbracelet/gum" + exit 1 +fi + +# Define variables +NF_BASE_URL="https://github.com/ryanoasis/nerd-fonts/releases/download" +NF_VERSION=$(curl -sL https://github.com/ryanoasis/nerd-fonts/releases/latest | grep "Release" | awk '{ print $2 }') +NF_URL="${NF_BASE_URL}/${NF_VERSION}" +LOCAL_FONT_DIR="${HOME}/.local/share/fonts" + +# Fancy error output message. +gum_error() { + gum style \ + --foreground 3 \ + --border-foreground 203 \ + --border rounded \ + --align center \ + --width 50 \ + --margin "1 2" \ + "ERROR" \ + "" \ + "$1" + exit 1 +} + +# Array of nerd font names. +nf_array=( + 3270 + Agave + AnonymousPro + Arimo + AurulentSansMono + BigBlueTerminal + BitstreamVeraSansMono + CascadiaCode + CodeNewRoman + Cousine + DaddyTimeMono + DejaVuSansMono + DroidSansMono + FantasqueSansMono + FiraCode + FiraMono + Go-Mono + Gohu + Hack + Hasklig + HeavyData + Hermit + iA-Writer + IBMPlexMono + Inconsolata + InconsolataGo + InconsolataLGC + Iosevka + JetBrainsMono + Lekton + LiberationMono + Meslo + Monofur + Monoid + Mononoki + MPlus + Noto + OpenDyslexic + Overpass + ProFont + ProggyClean + RobotoMono + ShareTechMono + SourceCodePro + SpaceMono + Terminus + Tinos + Ubuntu + UbuntuMono + VictorMono +) + +# Print the startup message. +message=$(echo "Nerd font installer :nerd_face:" | gum format -t emoji) +gum style \ + --foreground 212 \ + --border-foreground 57 \ + --border rounded \ + --align center \ + --width 50 \ + --margin "1 2" \ + "$message" + +# Print the `nf_array` line by line and pipe to `gum choose --no-limit`. +# Create `selection` array from the output of `gum choose --no-limit`. +# It will contain only the items that were selected by the user. +selection=($(printf "%s\n" "${nf_array[@]}" | gum choose --no-limit)) + +# Prompt for user confirmation and proceed with installation of nerd fonts. +# +# For each nerd font selected, print a status message while downloading and +# installing the nerd font. Else print an error message if any of it fails. +# +# If user declines to proceed with installation, print a cancel message. +if gum confirm "Proceed with installation?"; then + for item in "${selection[@]}"; do + if ! gum spin --spinner dot --title "Downloading $item..." \ + -- curl --create-dirs -f -sL -o "${LOCAL_FONT_DIR}/$item.zip" "${NF_URL}/$item.zip"; then + gum_error "Failed to download nerd font archive $item" + fi + if ! gum spin --spinner dot --title "Installing $item..." \ + -- unzip -uo "${LOCAL_FONT_DIR}/$item.zip" -d "${LOCAL_FONT_DIR}"; then + gum_error "Failed to install nerd font archive $item" + fi + done +else + gum style \ + --foreground 212 \ + --border-foreground 57 \ + --border rounded \ + --align center \ + --width 50 \ + --margin "1 2" \ + "Nerd font installation cancelled" +fi + +# Clean up local font directory. Removes everything besides fonts. +if ! gum spin --spinner dot --title "Cleaning up local font directory..." \ + -- find "${LOCAL_FONT_DIR}" -mindepth 1 \ + -not -name "*.otf" \ + -not -name "*.ttf" \ + -not -name "static" \ + -exec rm -rf {} \; ; then + gum_error "Failed to clean up local font directory. Try doing it manually." +fi + +# Update font cache +if ! gum spin --spinner dot --title "Updating font cache..." \ + -- fc-cache -f; then + gum_error "Failed to update font cache." +fi + +# Print a message stating which nerd fonts were installed. +gum format -t markdown -- \ + "# Successfully installed" \ + "$(printf "* %s\n" "${selection[@]}")" diff --git a/split-man b/split-man new file mode 100755 index 0000000..15e425b --- /dev/null +++ b/split-man @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Check if gum is available +if ! test -x "$(command -v gum)"; then + echo "Missing dependency: gum" + echo "See https://github.com/charmbracelet/gum" + exit 1 +fi + +CMD=$(gum input --placeholder="command") + +if [[ -n "$BYOBU_BACKEND" && "$BYOBU_BACKEND" = "tmux" ]]; then + byobu-tmux split-window -h man "$CMD" +elif [[ -n "$TMUX" ]]; then + tmux split-window -h man "$CMD" +elif [[ -n "$ZELLIJ" ]]; then + zellij action new-pane -- man "$CMD" +else + echo "No byobu, tmux, or Zellij sessions detected" + exit 1 +fi