From c1c1d8adbd04ac63b48c84e9a28cf0b5cd91f5e4 Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Thu, 13 Apr 2023 00:04:20 +0200 Subject: [PATCH] Scripts --- local/bin/Hyprland | 16 ++++++++++ local/bin/coless | 6 ++++ local/bin/glurp | 61 +++++++++++++++++++++++++++++++++++++ local/bin/miam | 53 ++++++++++++++++++++++++++++++++ local/bin/mkddate | 5 +++ local/bin/mount-phone | 24 +++++++++++++++ local/bin/sensible-browser | 7 +++++ local/bin/ssh-fwd | 58 +++++++++++++++++++++++++++++++++++ local/bin/sshot-file | 5 +++ local/bin/sway | 25 +++++++++++++++ local/bin/swaylock | 29 ++++++++++++++++++ local/bin/update-grub | 4 +++ local/bin/updateall | 25 +++++++++++++++ local/bin/vncctl | 33 ++++++++++++++++++++ local/bin/vncsconnect | 35 +++++++++++++++++++++ local/bin/waybar | 19 ++++++++++++ local/bin/weston-rdp | 35 +++++++++++++++++++++ local/bin/wolf | 53 ++++++++++++++++++++++++++++++++ local/bin/xdg-session-start | 8 +++++ 19 files changed, 501 insertions(+) create mode 100755 local/bin/Hyprland create mode 100755 local/bin/coless create mode 100755 local/bin/glurp create mode 100755 local/bin/miam create mode 100755 local/bin/mkddate create mode 100755 local/bin/mount-phone create mode 100755 local/bin/sensible-browser create mode 100755 local/bin/ssh-fwd create mode 100755 local/bin/sshot-file create mode 100755 local/bin/sway create mode 100755 local/bin/swaylock create mode 100755 local/bin/update-grub create mode 100755 local/bin/updateall create mode 100755 local/bin/vncctl create mode 100755 local/bin/vncsconnect create mode 100755 local/bin/waybar create mode 100755 local/bin/weston-rdp create mode 100755 local/bin/wolf create mode 100755 local/bin/xdg-session-start diff --git a/local/bin/Hyprland b/local/bin/Hyprland new file mode 100755 index 0000000..365d840 --- /dev/null +++ b/local/bin/Hyprland @@ -0,0 +1,16 @@ +#!/bin/sh -xe + +# cd to home +cd + +# Add the Wayland version of Wine to the path +export PATH="/opt/wine-wl/usr/bin:$PATH" + +# Set librewolf as default browser +export BROWSER=librewolf + +# Execution +dbus-launch --exit-with-session \ + ssh-agent \ + /usr/bin/Hyprland + diff --git a/local/bin/coless b/local/bin/coless new file mode 100755 index 0000000..f9b50ca --- /dev/null +++ b/local/bin/coless @@ -0,0 +1,6 @@ +#!/bin/sh +env \ + LESSOPEN='| /usr/bin/src-hilite-lesspipe.sh %s' \ + LESS=' -R ' \ + less "$@" + diff --git a/local/bin/glurp b/local/bin/glurp new file mode 100755 index 0000000..f387df9 --- /dev/null +++ b/local/bin/glurp @@ -0,0 +1,61 @@ +#!/bin/bash + +# Functions +# Error +function error { + >&2 echo -e "\033[1;31mERROR:\033[0m $1"; shift + exit "${1:-1}" +} + +# Throw a value +function throw-value { + error "Value \"${1}\" invalid for ${2}." 1 +} + +function screenshot-path { + printf '%s%s-screenshot-%s.png' "${screenshot_d}/" "${LOGNAME}" "$(date +'%Y_%m_%d_%s')" +} + +# Variables +declare -a prepend _command append +screenshot_d=/tmp + +# Arguments +selection_mode="$1"; shift +saving_mode="$1" ; shift + +# Command building +_command+=(grim) +case "$selection_mode" in + full) + : + ;; + area) + _command+=(-g -) + prepend+=(slurp) + ;; + *) + throw-value "$selection_mode" 'selection mode' + ;; +esac +case "$saving_mode" in + clip) + _command+=(-) + append+=(wl-copy -t image/png) + ;; + file) + _command+=("$(screenshot-path)") + ;; + *) + throw-value "$saving_mode" 'saving mode' + ;; +esac + +# Debug +#echo "${prepend[@]} | ${_command[@]} | ${append[@]}" +#exit 0 + +# Execution +set -xe +"${prepend[@]}" | "${_command[@]}" | "${append[@]}" + diff --git a/local/bin/miam b/local/bin/miam new file mode 100755 index 0000000..cc6d2e0 --- /dev/null +++ b/local/bin/miam @@ -0,0 +1,53 @@ +#!/bin/bash + +# Functions +# Throw +function throw { + >&2 echo "$1" + exit "$2" +} + +# Throw a value +function throw-value { + throw "Invalid value for \"$1\": \"$2\"" "$3" +} + +# Variables +selection_mode="$1" +saving_mode="$2" +screenshot_d="/tmp" +_command=() + +# Command building +_command+=("maim") +case "$selection_mode" in + "full") + : + ;; + "area") + _command+=("-s") + ;; + *) + throw-value "selection mode" "$selection_mode" 1 + ;; +esac +case "$saving_mode" in + "clip") + _command+=("|") + _command+=("xclip" "-selection" "clipboard" "-t" "image/png") + ;; + "file") + _command+=(">" "${screenshot_d}/$(printf '%s-screenshot-%s.png' "$LOGNAME" "$(date +'%Y_%m_%d_%s')")") + ;; + *) + throw-value "saving mode" "$saving_mode" 2 + ;; +esac + +# Debug +#echo "${_command[@]}" +#exit 0 + +# Execution +"${_command[@]}" + diff --git a/local/bin/mkddate b/local/bin/mkddate new file mode 100755 index 0000000..20a2dff --- /dev/null +++ b/local/bin/mkddate @@ -0,0 +1,5 @@ +#!/bin/sh -e +path="${1:-.}/$(date +'%Y_%m_%d')" +mkdir -p "$path" +echo "$path" + diff --git a/local/bin/mount-phone b/local/bin/mount-phone new file mode 100755 index 0000000..3f5d7d1 --- /dev/null +++ b/local/bin/mount-phone @@ -0,0 +1,24 @@ +#!/bin/bash + +# Variable +dest="/mnt/ahurac/phone" + +# Commands building +# Create destination +create_destination=( + mkdir + -p + "$dest" +) + +# Mount phone +mount_phone=( + aft-mtp-mount + "$dest" +) + +# Execution +set -xe +"${create_destination[@]}" +"${mount_phone[@]}" + diff --git a/local/bin/sensible-browser b/local/bin/sensible-browser new file mode 100755 index 0000000..8803e26 --- /dev/null +++ b/local/bin/sensible-browser @@ -0,0 +1,7 @@ +#!/bin/sh +if [ -n "$BROWSER" ]; then + exec "$BROWSER" +else + exit 127 +fi + diff --git a/local/bin/ssh-fwd b/local/bin/ssh-fwd new file mode 100755 index 0000000..465a704 --- /dev/null +++ b/local/bin/ssh-fwd @@ -0,0 +1,58 @@ +#!/bin/bash -e + +shopt -s expand_aliases +[[ $TERM = xterm-kitty ]] && alias ssh='kitty +kitten ssh' + +# Variables +ssh=ssh +declare -a args + +# Display the usage +function usage { + cat << EOF +Usage: $(basename "$0") SSH_HOST LOCAL_PORT DISTANT_PORT [TARGET] [-- SSH_OPTIONS] +EOF +} + +function error { + >&2 usage + exit "${1:-1}" +} + +# Arguments +while [[ -n $* ]]; do + case "$1" in + "--") + shift + ssh_options=("$@") + set -- + ;; + *) + args+=("$1") + shift + ;; + esac +done + +# Checking the validity of the args +[[ -z ${args[2]} ]] && error 1 +[[ -z ${args[3]} ]] && args[3]=localhost + +# Command building +ssh_com=( + "$ssh" + "${ssh_options[@]}" + -f + -N + -L "${args[1]}:${args[3]}:${args[2]}" + "${args[0]}" +) + +# Debug +#echo "${ssh_com[@]}" +#exit 0 + +# Execution +set -x +"${ssh_com[@]}" + diff --git a/local/bin/sshot-file b/local/bin/sshot-file new file mode 100755 index 0000000..eb77f8a --- /dev/null +++ b/local/bin/sshot-file @@ -0,0 +1,5 @@ +#!/bin/sh +exec printf \ + "screenshot-%s.${1:-png}" \ + "$(date +"%Y_%m_%d-%N")" + diff --git a/local/bin/sway b/local/bin/sway new file mode 100755 index 0000000..9e6ff33 --- /dev/null +++ b/local/bin/sway @@ -0,0 +1,25 @@ +#!/bin/sh -xe + +# cd +cd + +# Environment +# XDG +export \ + XDG_CURRENT_DESKTOP=sway \ + XDG_SESSION_DESKTOP=sway + +# Backends +export \ + QT_QPA_PLATFORM='wayland;xcb' \ + QT_QPA_PLATFORMTHEME=qt6ct \ + CLUTTER_BACKEND=wayland \ + SDL_VIDEODRIVER=wayland \ + _JAVA_AWT_WM_NONREPARENTING=1 \ + MOZ_ENABLE_WAYLAND=1 + +# Execution +exec dbus-launch --exit-with-session \ + ssh-agent \ + /usr/bin/sway + diff --git a/local/bin/swaylock b/local/bin/swaylock new file mode 100755 index 0000000..46a8e2d --- /dev/null +++ b/local/bin/swaylock @@ -0,0 +1,29 @@ +#!/bin/sh + +# Run swaylock +exec /usr/bin/swaylock \ + --daemonize \ + --indicator \ + --clock \ + --screenshots \ + --effect-blur 20x10 \ + --indicator-radius 100 \ + --font 'Hack Nerd Font' \ + --bs-hl-color '#FF3366' \ + --inside-color '#CC99FF22' \ + --inside-clear-color '#F3E6FFDD' \ + --inside-ver-color '#9933FF22' \ + --inside-wrong-color '#FF336622' \ + --key-hl-color '#9933FF' \ + --text-color '#F3E6FF' \ + --text-caps-lock-color '#FFB3C6' \ + --line-uses-ring \ + --ring-color '#1A0033' \ + --ring-clear-color '#9933FF' \ + --ring-ver-color '#4F0099' \ + --ring-wrong-color '#800020' \ + --text-clear-color '#4F0099' \ + --text-ver-color '#F3E6FF' \ + --text-wrong-color '#FFB3C6' \ + --separator-color '#00000000' + diff --git a/local/bin/update-grub b/local/bin/update-grub new file mode 100755 index 0000000..e026dc9 --- /dev/null +++ b/local/bin/update-grub @@ -0,0 +1,4 @@ +#!/bin/sh +grub-mkconfig \ + -o /boot/grub/grub.cfg + diff --git a/local/bin/updateall b/local/bin/updateall new file mode 100755 index 0000000..1a6ee01 --- /dev/null +++ b/local/bin/updateall @@ -0,0 +1,25 @@ +#!/bin/bash + +# Variable +commands_d="$HOME/.local/share/updateall/commands.d" + +# Function +# Create a clear separator, adapts to the screen size +function separator { + local char="${2:-=}" + local separator cols + (( cols = $(tput cols) / 3 )) + + while [[ ${#separator} -le $cols ]]; do + separator+="$char" + done + + printf '\n%s\n\t%s\n%s\n' "$separator" "$1" "$separator" +} + +# Loop +for pm in "$commands_d/"*; do + separator "$(basename "$pm")" + source "$pm" +done + diff --git a/local/bin/vncctl b/local/bin/vncctl new file mode 100755 index 0000000..da9790f --- /dev/null +++ b/local/bin/vncctl @@ -0,0 +1,33 @@ +#!/bin/bash + +# Variables +declare -a vncctl +systemctl=systemctl +systemd_unit=vncserver +verb="${1:-status}"; shift +display="${1:-1}" ; shift + +# Prepending sudo if necessary +case "$verb" in + start|restart|stop) + sudo=sudo + ;; +esac + +# Command building +[[ -n $sudo ]] && vncctl+=("$sudo") +vncctl+=( + "$systemctl" + "$@" + "$verb" + "${systemd_unit}@:${display}" +) + +# Debug +#echo "${vncctl[@]}" +#exit 0 + +# Command execution +set -xe +"${vncctl[@]}" + diff --git a/local/bin/vncsconnect b/local/bin/vncsconnect new file mode 100755 index 0000000..4abe354 --- /dev/null +++ b/local/bin/vncsconnect @@ -0,0 +1,35 @@ +#!/bin/bash + +# Variables +declare -a make_ssh_bridge open_vnc_session +ssh_fwd=ssh-fwd +vncviewer=vncviewer +localhost=localhost + +# Arguments +ssh_host="$1" +local_port="${2:-9900}" +distant_port="${3:-5900}" +target="$4" + +# Commands building +# Make SSH bridge +make_ssh_bridge+=( + "$ssh_fwd" + "$ssh_host" + "$local_port" + "$distant_port" + "$target" +) + +# Open VNC session +open_vnc_session+=( + "$vncviewer" + "${localhost}:${local_port}" +) + +# Execution +set -xe +"${make_ssh_bridge[@]}" +"${open_vnc_session[@]}" + diff --git a/local/bin/waybar b/local/bin/waybar new file mode 100755 index 0000000..f0c7b3c --- /dev/null +++ b/local/bin/waybar @@ -0,0 +1,19 @@ +#!/bin/sh -x +# Waybar wrapper to reload it anytime the +# configuration is edited + +# Variable +waybar_config_d="${HOME}/.config/waybar" +monitored_events=( + modify + create + delete +) + +# Execution +while :; do + /usr/bin/waybar "$@" & + inotifywait "${monitored_events[@]/#/-e}" "${waybar_config_d}" + jobs -p | xargs kill +done + diff --git a/local/bin/weston-rdp b/local/bin/weston-rdp new file mode 100755 index 0000000..40a6d7e --- /dev/null +++ b/local/bin/weston-rdp @@ -0,0 +1,35 @@ +#!/bin/bash + +# Variables +weston=weston +backend=rdp-backend.so +rdp_d="${HOME}/.rdp" +hostname="$(hostname)" +crt="${rdp_d}/${hostname}.crt" +key="${rdp_d}/${hostname}.key" +socket=wayland-1 + +# Arguments +width="${1:-1920}" ; shift +height="${1:-1080}"; shift + +# Command building +weston_com=( + "$weston" + "--backend=${backend}" + "--rdp-tls-cert=${crt}" + "--rdp-tls-key=${key}" + "--width=${width}" + "--height=${height}" + "--socket=${socket}" +) + +# Debug +#echo "${weston_com[@]}" +#exit 0 + +# Execution +set -xe +cd +"${weston_com[@]}" + diff --git a/local/bin/wolf b/local/bin/wolf new file mode 100755 index 0000000..1cea48e --- /dev/null +++ b/local/bin/wolf @@ -0,0 +1,53 @@ +#!/bin/bash + +# Arguments +hostname="$1"; shift + +# Variables +declare mac +declare -a wol_com options +name="$(basename "$0")" +wolf_d="${HOME}/.wolf" +wolf_host="${wolf_d}/${hostname}" + +# Functions +# Throw an error +function error { + >&2 echo -e "${name}: \033[1;31mERROR:\033[0m ${1:-No further details}"; shift + exit "${1:-1}" +} + +# Parse variable in options file +function getvar { + grep '^'"$1"' ' "$wolf_host" | cut -d ' ' -f 2 +} + +# Parsing +[[ -f $wolf_host ]] || error "\"${hostname}\": No such host" + +# Assign the options +mac="$(getvar Mac)" +ip="$(getvar IP)" +port="$(getvar Port)" + +# Add options if necessary +[[ -n $ip ]] && options+=(-i "$ip" ) +[[ -n $port ]] && options+=(-p "$port") + +# Commands building +# wol +wol_com=( + wol + "$@" + "${options[@]}" + "$mac" +) + +# Debug +#echo "${wol_com[@]}" +#exit 0 + +# Execution +set -xe +"${wol_com[@]}" + diff --git a/local/bin/xdg-session-start b/local/bin/xdg-session-start new file mode 100755 index 0000000..8a49016 --- /dev/null +++ b/local/bin/xdg-session-start @@ -0,0 +1,8 @@ +#!/bin/sh +/usr/lib/xdg-desktop-portal-wlr & +dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP +sleep 1 +artix-pipewire-loader & +sleep 1 +waybar +