diff options
Diffstat (limited to '.local/bin/scripts')
| -rwxr-xr-x | .local/bin/scripts/Heads-Up-Display | 28 | ||||
| -rw-r--r-- | .local/bin/scripts/README.md | 1 | ||||
| -rwxr-xr-x | .local/bin/scripts/bspwm_resize.sh | 67 | ||||
| -rw-r--r-- | .local/bin/scripts/check-updates.sh | 0 | ||||
| -rwxr-xr-x | .local/bin/scripts/colors.sh | 78 | ||||
| -rwxr-xr-x | .local/bin/scripts/cryptocheck | 31 | ||||
| -rwxr-xr-x | .local/bin/scripts/cryptonotify | 19 | ||||
| -rwxr-xr-x | .local/bin/scripts/dotfiles.sh | 37 | ||||
| -rwxr-xr-x | .local/bin/scripts/ffmpeg | 24 | ||||
| -rwxr-xr-x | .local/bin/scripts/get_zle_keymap_select.sh | 13 | ||||
| -rw-r--r-- | .local/bin/scripts/install.sh | 19 | ||||
| -rwxr-xr-x | .local/bin/scripts/killandnotify | 4 | ||||
| -rwxr-xr-x | .local/bin/scripts/layer.sh | 24 | ||||
| -rwxr-xr-x | .local/bin/scripts/opacity-change.sh | 34 | ||||
| -rwxr-xr-x | .local/bin/scripts/powermenu | 38 | ||||
| -rwxr-xr-x | .local/bin/scripts/qemu-helper.sh | 172 | ||||
| -rwxr-xr-x | .local/bin/scripts/scratchpad | 68 | ||||
| -rw-r--r-- | .local/bin/scripts/win-nvim.bat | 37 | ||||
| -rw-r--r-- | .local/bin/scripts/win-nvim.ps1 | 39 |
19 files changed, 733 insertions, 0 deletions
diff --git a/.local/bin/scripts/Heads-Up-Display b/.local/bin/scripts/Heads-Up-Display new file mode 100755 index 0000000..8680123 --- /dev/null +++ b/.local/bin/scripts/Heads-Up-Display @@ -0,0 +1,28 @@ +#!/bin/sh + +# Created By: srdusr +# Created On: Wed 05 Feb 2023 01:24:37 AM CAT +# Project: bspwm scratchpad (Heads-Up-Display) with tmux session + +if id="$(xdo id -N Heads-Up-Display)" + then bspc node "$id" -g hidden -f + else kitty --class "Heads-Up-Display" -e tmux new-session -A -s HUD -e bash > /dev/null 2>&1 & +fi + +#- - - - - - - - - - + + +### Alternative method + +#id=$(xdotool search --class Heads-Up-Display); +#if [ -z "$id" ]; then +# #kitty --class "Heads-Up-Display" -e tmux new-session -A -s HUD -e bash > /dev/null 2>&1 & +# alacritty --class "Heads-Up-Display" -e tmux new-session -A -s HUD -e bash > /dev/null 2>&1 & +#else +# if [ ! -f /tmp/hide_hud ]; then +# touch /tmp/hide_hud && xdo hide "$id" +# elif [ -f /tmp/hide_hud ]; then +# rm /tmp/hide_hud && xdo show "$id" +# fi +#fi + diff --git a/.local/bin/scripts/README.md b/.local/bin/scripts/README.md new file mode 100644 index 0000000..458b3cc --- /dev/null +++ b/.local/bin/scripts/README.md @@ -0,0 +1 @@ +# scripts diff --git a/.local/bin/scripts/bspwm_resize.sh b/.local/bin/scripts/bspwm_resize.sh new file mode 100755 index 0000000..29ab5cf --- /dev/null +++ b/.local/bin/scripts/bspwm_resize.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +size=${2:-'10'} +dir=$1 + +# Find current window mode +is_tiled() { +bspc query -T -n | grep -q '"state":"tiled"' +} +# If the window is floating, move it +if ! is_tiled; then +#only parse input if window is floating,tiled windows accept input as is + case "$dir" in + west) switch="-w" + sign="-" + ;; + east) switch="-w" + sign="+" + ;; + north) switch="-h" + sign="-" + ;; + south) switch="-h" + sign="+" + ;; + esac + xdo resize ${switch} ${sign}${size} + +# Otherwise, window is tiled: switch with window in given direction +else + case "$dir" in + west) bspc node @west -r -$size || bspc node @east -r -${size} + ;; + east) bspc node @west -r +$size || bspc node @east -r +${size} + ;; + north) bspc node @south -r -$size || bspc node @north -r -${size} + ;; + south) bspc node @south -r +$size || bspc node @north -r +${size} + ;; + esac +fi + +##!/bin/bash +# +#[ "$#" -eq 3 ] || { echo "Needs exactly three arguments."; exit 1; } +# +#motion="$1" +#direction="$2" +#size="$3" +# +#if [ "$motion" = 'expand' ]; then +# # These expand the window's given side +# case "$direction" in +# north) bspc node -z top 0 -"$size" ;; +# east) bspc node -z right "$size" 0 ;; +# south) bspc node -z bottom 0 "$size" ;; +# west) bspc node -z left -"$size" 0 ;; +# esac +#else +# # These contract the window's given side +# case "$direction" in +# north) bspc node -z top 0 "$size" ;; +# east) bspc node -z right -"$size" 0 ;; +# south) bspc node -z bottom 0 -"$size" ;; +# west) bspc node -z left "$size" 0 ;; +# esac +#fi diff --git a/.local/bin/scripts/check-updates.sh b/.local/bin/scripts/check-updates.sh new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.local/bin/scripts/check-updates.sh diff --git a/.local/bin/scripts/colors.sh b/.local/bin/scripts/colors.sh new file mode 100755 index 0000000..fc1c10c --- /dev/null +++ b/.local/bin/scripts/colors.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +colors=$@ +for (( n=0; n < $colors; n++ )) do + printf " [%d] $(tput setaf $n)%s$(tput sgr0)" $n "Hello World! +" +done +PADDING='Padding' + +main() { + local xterm_start=0 \ + xterm_width=8 \ + xterm_height=2 + + local cube_start=$((xterm_start + xterm_width * xterm_height)) \ + cube_width=6 \ + cube_height=$((6 * 6)) + + local greys_start=$((cube_start + cube_width * cube_height)) \ + greys_width=8 \ + greys_height=3 + + color_block $xterm_start $xterm_width $xterm_height + color_block $cube_start $cube_width $cube_height use_padding + color_block $greys_start $greys_width $greys_height + echo +} + +color_block() { + local start=$1 width=$2 height=$3 use_padding=$4 + local max s color_nums colors + + max=$((start + width * height - 1)) + + echo + for s in $(seq $start $width $max); do + color_nums=$(seq $s $((s + width - 1))) + colors="${use_padding:+$PADDING }${color_nums}${use_padding:+ $PADDING}" + + printf '%s%s %s%s\n' \ + "$(fg_bars $colors)" $ansi_reset \ + "$(bg_bars $colors)" $ansi_reset + done +} + +fg_bars() { + for color in $@; do + color_bar ansi_fg $color '' + done +} + +bg_bars() { + for color in $@; do + color_bar ansi_bg $color ' ' + done +} + +color_bar() { + local ansi=$1 color=$2 trail=$3 + + if [ "$color" == $PADDING ]; then + printf '%s %s' $ansi_reset "$trail" + else + local color_seq=$($ansi $color) + printf '%s %03d%s' $color_seq $color "$trail" + fi +} + +ansi_reset=$'\033[0m' + +ansi_fg() { + printf '\033[38;5;%dm' $1 +} + +ansi_bg() { + printf '\033[48;5;%dm' $1 +} + +main diff --git a/.local/bin/scripts/cryptocheck b/.local/bin/scripts/cryptocheck new file mode 100755 index 0000000..02ba42d --- /dev/null +++ b/.local/bin/scripts/cryptocheck @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +if [ ! -d ~/.cache/crypto ]; then + mkdir ~/.cache/crypto +fi +ticker=(BTC ETH ADA DOT SOL XMR) + +for currency in "${ticker[@]}"; do + echo "$currency" +done | while read coin + do + price=$(curl rate.sx/1$coin) + if [ $coin = "BTC" ]; then + icon= + elif [ $coin = "ETH" ]; then + icon= + elif [ $coin = "ADA" ]; then + icon= + elif [ $coin = "DOT" ]; then + icon= + elif [ $coin = "SOL" ]; then + icon= + elif [ $coin = "XMR" ]; then + icon= + fi + + echo "$icon $coin: $price" > ~/.cache/crypto/$coin + + done + +date > ~/.cache/crypto/time + diff --git a/.local/bin/scripts/cryptonotify b/.local/bin/scripts/cryptonotify new file mode 100755 index 0000000..47883c3 --- /dev/null +++ b/.local/bin/scripts/cryptonotify @@ -0,0 +1,19 @@ +#!/bin/sh +source cryptocheck +Output= +for file in ~/.cache/crypto/* +do + if [ ! -z "$Output" ]; then + if [ ! $(basename $file) = "time" ]; then + Output="$Output\n$(cat $file)" + fi + else + if [ ! $(basename $file) = "time" ]; then + Output="$Output$(cat $file)" + fi + fi + +done + +Output="$Output\n$(cat ~/.cache/crypto/time)" +notify-send "Crypto Prices" "$Output" diff --git a/.local/bin/scripts/dotfiles.sh b/.local/bin/scripts/dotfiles.sh new file mode 100755 index 0000000..b231367 --- /dev/null +++ b/.local/bin/scripts/dotfiles.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Set the bare dotfiles repo directory +dotfiles_dir="$HOME/.cfg" + +# Set the home directory +home_dir="$HOME" + +# Exclude the .cfg directory and any other files/directories you want to ignore +exclude_list=(".cfg") + +# Change to the home directory +cd "$home_dir" + +# Get a list of all dotfiles in the repository +files=$(find "$dotfiles_dir" -maxdepth 1 -type f -not -name ".*" -not -name "${exclude_list[*]}" -printf "%f\n") + +# Link each file to its corresponding location in $HOME +for file in $files; do + ln -sf "$dotfiles_dir/$file" "$home_dir/.$file" +done + +# Get a list of all dot directories in the repository +dirs=$(find "$dotfiles_dir" -maxdepth 1 -type d -not -path "$dotfiles_dir" -not -name ".*" -not -name "${exclude_list[*]}" -printf "%f\n") + +# Link each directory to its corresponding location in $HOME +for dir in $dirs; do + ln -sf "$dotfiles_dir/$dir" "$home_dir/.$dir" +done + +# Remove any symlinks that are no longer present in the repo +while IFS= read -r -d '' link; do + if [[ ! -e "$link" ]]; then + rm "$link" + fi +done < <(find "$home_dir" -maxdepth 1 -type l -name ".*" -not -name ".cfg" -print0) + diff --git a/.local/bin/scripts/ffmpeg b/.local/bin/scripts/ffmpeg new file mode 100755 index 0000000..2258fbd --- /dev/null +++ b/.local/bin/scripts/ffmpeg @@ -0,0 +1,24 @@ +#!/bin/bash + +# audio +A="$(pactl list sources | grep 'analog.*monitor' | awk '{print $2}')" +# screen size +S="$(xdpyinfo | grep dimensions | awk '{print $2}')" +# file name +N="$(date +"%m-%d-%Y_%I:%M%p").mp4" + +# Desktop audio + screen recording +ffmpeg \ +-s "$S" -r 25 -f x11grab -i :0.0+0,0 \ +-ac 2 ~/"$N" + +# ffmpeg can output high quality GIF. Before you start it is always recommended to use a recent version: download or compile. + +# ffmpeg -ss 30 -t 3 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif + +# This example will skip the first 30 seconds (-ss 30) of the input and create a 3 second output (-t 3). +# fps filter sets the frame rate. A rate of 10 frames per second is used in the example. +# scale filter will resize the output to 320 pixels wide and automatically determine the height while preserving the aspect ratio. The lanczos scaling algorithm is used in this example. +# palettegen and paletteuse filters will generate and use a custom palette generated from your input. These filters have many options, so refer to the links for a list of all available options and values. Also see the Advanced options section below. +# split filter will allow everything to be done in one command and avoids having to create a temporary PNG file of the palette. +# Control looping with -loop output option but the values are confusing. A value of 0 is infinite looping, -1 is no looping, and 1 will loop once meaning it will play twice. So a value of 10 will cause the GIF to play 11 times. diff --git a/.local/bin/scripts/get_zle_keymap_select.sh b/.local/bin/scripts/get_zle_keymap_select.sh new file mode 100755 index 0000000..1e2eaf4 --- /dev/null +++ b/.local/bin/scripts/get_zle_keymap_select.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Get the value of the zle-keymap-select variable +value=$(print -v zle-keymap-select) + +# Specify the file path to save the value +file_path="~/file.txt" + +# Write the value to the file +echo "$value" > "$file_path" + +# Optionally, you can also print the value to the console +echo "The value of zle-keymap-select is: $value" diff --git a/.local/bin/scripts/install.sh b/.local/bin/scripts/install.sh new file mode 100644 index 0000000..b811355 --- /dev/null +++ b/.local/bin/scripts/install.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [[ $EUID -eq 0 ]]; then + echo "This script must not be run as root" + exit 1 +fi + +# Install system packages +packages=( + "ripgrep" + "xclip" + "ctags" +) + +for package in "${packages[@]}"; do + if ! pacman -Qi "$package" > /dev/null 2>&1; then + sudo pacman -S --noconfirm "$package" + fi +done diff --git a/.local/bin/scripts/killandnotify b/.local/bin/scripts/killandnotify new file mode 100755 index 0000000..2e7222e --- /dev/null +++ b/.local/bin/scripts/killandnotify @@ -0,0 +1,4 @@ +#!/bin/sh +# Kills an application and sends a notification that it's been killed + +killall "$1" && notify-send "$1" "$2" diff --git a/.local/bin/scripts/layer.sh b/.local/bin/scripts/layer.sh new file mode 100755 index 0000000..4b17ed1 --- /dev/null +++ b/.local/bin/scripts/layer.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +current_layer="$(bspc query -T -n | jq -r '.client.layer')" +case $1 in + +|-) + declare -A _layers=( [below]=0 [normal]=1 [above]=2 ) + layers=( below normal above ) + maxl=$(( ${#layers[@]} - 1 )) + current_layer="$(bspc query -T -n | jq -r '.client.layer')" + i=$(( ${_layers[$current_layer]} $1 1 )) + if [[ $i -lt 0 ]]; then + i=0 + elif [[ $i -gt $maxl ]]; then + i=$maxl + fi + #cycle? nah + #i=$(( (${_layers[$current_layer]} + ${#layers[@]} ${1} 1) % ${#layers[@]} )) + new_layer="${layers[$i]}" + ;; + *) + new_layer="$(bspc query -T -n | jq -r '.client.lastLayer')" + ;; +esac +[[ "$current_layer" != "$new_layer" ]] && bspc node -l "$new_layer" diff --git a/.local/bin/scripts/opacity-change.sh b/.local/bin/scripts/opacity-change.sh new file mode 100755 index 0000000..b509936 --- /dev/null +++ b/.local/bin/scripts/opacity-change.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -eu +[[ -n ${DEBUG:-} ]] && set -x + +#### Example alacritty.yml usage +#key_bindings: +# - { key: N, mods: Control|Shift, action: SpawnNewInstance } +# - { key: O, mods: Control|Shift, command: { program: "opacity-change.sh", args: ["-"] } } +# - { key: P, mods: Control|Shift, command: { program: "opacity-change.sh", args: ["+"] } } + + +operation="${1:-}${2:-}" # Arg #1 & #2 (in case the user misinterpreted a space in the usage), Default '' +step="${operation:1}" # Substring from char index 1 +step="${step:-1}" # Default '1' +operation="${operation:0:1}" # Substring from char index 0 length of 1 +config_file="$HOME/.config/alacritty/alacritty.yml" +config_field="opacity" +tmp_file="/tmp/$(basename $config_file).$(date +%s)" +current_value=$(sed 's/#.*//g; /\b'"$config_field"':/!d; s/.*: \?//' < "$config_file") + +case $operation in +"-") + verb="Decreasing" ;; +"+") + verb="Increasing" ;; +*) + echo "Usage: ${BASH_SOURCE[0]} (-|+)[int]"; exit 255 ;; +esac + +new_value="$(awk '{n=$1+$2/10; print (n<0 ? 0 : n>1 ? 1 : n)}' <<<"$current_value $operation$step")" +echo "$verb $config_field from $current_value to $new_value" >&2 +cp "$config_file" "$tmp_file" +sed "s/\b$config_field:.*/$config_field: $new_value/" "$tmp_file" > "$config_file" + diff --git a/.local/bin/scripts/powermenu b/.local/bin/scripts/powermenu new file mode 100755 index 0000000..7bd913e --- /dev/null +++ b/.local/bin/scripts/powermenu @@ -0,0 +1,38 @@ +#!/bin/bash + +# display a power menu to: shutdown, reboot, +# lock, logout, and suspend. This script can be +# executed by clicking on the polybar powermenu module +# or with a keyboard shortcut + +# options to be displayed +shutdown=" Shutdown" +reboot=" Reboot" +lock=" Lock" +logout=" Logout" +suspend=" Suspend" + +uptime=$(uptime -p | sed -e 's/up //g') + +# options passed into variable +options="$shutdown\n$reboot\n$lock\n$logout\n$suspend" + +chosen="$(echo -e "$options" | rofi -theme ~/.config/rofi/styles/powermenu.rasi -lines 5 -dmenu -p "$uptime")" + +case $chosen in +$shutdown) + systemctl poweroff + ;; +$reboot) + systemctl reboot + ;; +$lock) + betterlockscreen --lock dimblur + ;; +$logout) + bspc quit + ;; +$suspend) + systemctl suspend + ;; +esac diff --git a/.local/bin/scripts/qemu-helper.sh b/.local/bin/scripts/qemu-helper.sh new file mode 100755 index 0000000..0d38aba --- /dev/null +++ b/.local/bin/scripts/qemu-helper.sh @@ -0,0 +1,172 @@ +#!/bin/bash + +# Created By: srdusr +# Created On: Wed 02 Aug 2023 16:16:21 PM CAT +# Project: QEMU setup/opener helper wrapper script + +# Set global variables for VM parameters +ram_size="4G" + +# Function to prompt user for VM parameters +function get_vm_parameters() { + read -p "Enter VM name (default: vm): " vm_name + vm_name=${vm_name:-vm} + + # Set the default ISO file path to ~/machines/images + default_iso_path="$HOME/machines/images" + + # Generate completions for ISO and IMG files in the images directory + COMPREPLY=() + local files=$(compgen -G "$default_iso_path/*.{iso,img}" -o plusdirs) + for file in $files; do + COMPREPLY+=("$file") + done + + # Use read with -i and -e options for tab-completion + read -ep "Enter ISO file path (default: $default_iso_path): " -i "$default_iso_path" iso_path + + # Manually expand the ~ to the user's home directory + iso_path=$(eval echo "$iso_path") + + # Validate the user input + while [ ! -f "$iso_path" ]; do + read -ep "Invalid file path. Enter a valid ISO file path: " iso_path + done + + # Check if the selected file is an IMG file + if [[ "$iso_path" == *.img ]]; then + guest_os="windows" + else + guest_os="linux" + fi + + # Show available disk space before asking for disk image size + echo "Available disk space:" + df -h "$vm_images_path" + + read -p "Enter disk image size in GB (default: 10G): " disk_size + disk_size=${disk_size:-10G} + + read -p "Enter RAM size in GB (default: 4G): " ram_size + ram_size=${ram_size:-4G} + + # Check if the RAM size is in the correct format (e.g., "4G") + while ! [[ $ram_size =~ ^[0-9]+[kKmMgGtTpPeE]$ ]]; do + read -p "Invalid RAM size format. Enter RAM size in GB (e.g., 4G): " ram_size + done + + read -p "Enter number of CPU cores (default: 2): " cpu_cores + cpu_cores=${cpu_cores:-2} +} + + +# Function to list available VMs +function list_vms() { + echo "Available VMs:" + for vm_file in "$vm_images_path"/*.qcow2; do + vm=$(basename "$vm_file" .qcow2) + echo " - $vm" + done +} + +# Function to list available ISO and IMG files in the images directory +function list_iso_img_files() { + echo "Available ISO and IMG files in $iso_images_path:" + iso_img_files=() + while IFS= read -r -d $'\0' file; do + iso_img_files+=("$file") + done < <(find "$iso_images_path" -type f \( -iname \*.iso -o -iname \*.img \) -print0) + + for ((i = 0; i < ${#iso_img_files[@]}; i++)); do + echo " $((i + 1)). ${iso_img_files[i]##*/}" + done +} + +# Function to check if VM is already running +function is_vm_running() { + vm_name=$1 + if ps aux | grep -v grep | grep -q "[q]emu-system-x86_64.*$vm_name"; then + return 0 + else + return 1 + fi +} + +# Function to start VM +function start_vm() { + vm_name=$1 + is_vm_running "$vm_name" + if [ $? -eq 0 ]; then + echo "VM '$vm_name' is already running." + return + fi + + # VM parameters + qemu_cmd="qemu-system-x86_64 -enable-kvm -machine type=q35 -m $ram_size -cpu host -smp 2 -vga virtio" + qemu_cmd+=" -device qemu-xhci -device usb-tablet -device usb-kbd -device virtio-net,netdev=user0 -netdev user,id=user0,hostfwd=tcp::5555-:22" + qemu_cmd+=" -cdrom \"$iso_path\" -drive file=\"$vm_images_path/$vm_name.qcow2\",index=0,media=disk,if=virtio" + + if [[ $guest_os == "windows" ]]; then + qemu_cmd+=" -drive file=\"$iso_images_path/virtio-win.iso\",index=3,media=cdrom" + fi + + qemu_cmd+=" -boot menu=on" + qemu_cmd+=" -net nic -net user,hostname=$vm_name -name \"$vm_name\"" + + echo "Starting VM: $vm_name" + eval "$qemu_cmd" +} + +# Main script starts here +vm_images_path="$HOME/machines/vm" +iso_images_path="$HOME/machines/images" + +# Check if directories exist +mkdir -p "$vm_images_path" +mkdir -p "$iso_images_path" + +# List available VMs +list_vms + +# List available ISO and IMG files in the images directory +list_iso_img_files + +# Ask the user if they want to use an existing VM or create a new one +read -p "Do you want to use an existing VM? (y/n): " use_existing_vm +if [[ $use_existing_vm =~ ^[Yy]$ ]]; then + read -p "Enter the name of the existing VM: " existing_vm_name + while [ ! -f "$vm_images_path/$existing_vm_name.qcow2" ]; do + echo "VM '$existing_vm_name' does not exist." + read -p "Enter a valid existing VM name: " existing_vm_name + done + vm_name=$existing_vm_name +else + # Prompt user for VM parameters + get_vm_parameters + + # Check if VM already exists + if [ -f "$vm_images_path/$vm_name.qcow2" ]; then + read -p "VM '$vm_name' already exists. Do you want to start it? (y/n): " start_vm_choice + if [[ $start_vm_choice =~ ^[Yy]$ ]]; then + start_vm "$vm_name" + exit 0 + fi + else + # Create new VM + echo "Creating new VM: $vm_name" + qemu-img create -f qcow2 "$vm_images_path/$vm_name.qcow2" "$disk_size" + start_vm "$vm_name" + exit 0 + fi +fi + +# If an existing VM is selected, ask if the user wants to modify its parameters +read -p "Do you want to modify the VM parameters? (y/n): " modify_vm_params +if [[ $modify_vm_params =~ ^[Yy]$ ]]; then + get_vm_parameters +fi + +# Start the VM +start_vm "$vm_name" + +echo "Script execution completed." diff --git a/.local/bin/scripts/scratchpad b/.local/bin/scripts/scratchpad new file mode 100755 index 0000000..1b3dfeb --- /dev/null +++ b/.local/bin/scripts/scratchpad @@ -0,0 +1,68 @@ +#!/bin/bash + +# Created By: srdusr +# Created On: Tue 07 Mar 2023 15:06:47 PM CAT +# Project: Agnostic scratchpad/dropdown terminal that works on most window managers + +# Set the GDK_BACKEND and QT_QPA_PLATFORM environment variables to x11 to allow working in Wayland +export GDK_BACKEND=x11 +export QT_QPA_PLATFORM=xcb + +# List of supported terminals with dropdown class +supported_terminals=( + "wezterm" + "kitty" + "alacritty" +) + +# Check if any of the supported terminals with scratchpad class are running +for term in "${supported_terminals[@]}"; do + if pgrep -f "$term.*--class scratchpad" >/dev/null; then + my_term="$term" + break + fi +done + +# If none of the supported terminals are running, start the first available one +if [ "$my_term" = "" ]; then + for term in "${supported_terminals[@]}"; do + if command -v "$term" >/dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ "$my_term" = "" ]; then + echo "No supported terminal found." + exit 1 + fi + + # Start the terminal with scratchpad class + case "$my_term" in + "wezterm") + wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "kitty") + kitty --class scratchpad tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "alacritty") + alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + esac +fi + +# Get the window ID of the scratchpad terminal +id="$(xdo id -N scratchpad)" + +# Toggle the visibility of the scratchpad terminal +if [ "$id" != "" ]; then + if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then + # The scratchpad window is visible, so hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" + xdo hide "$id" 2>/dev/null + else + # The scratchpad window is hidden, so show it + xdo show "$id" + # Restore the dimensions of the window + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null + fi +fi diff --git a/.local/bin/scripts/win-nvim.bat b/.local/bin/scripts/win-nvim.bat new file mode 100644 index 0000000..c99374d --- /dev/null +++ b/.local/bin/scripts/win-nvim.bat @@ -0,0 +1,37 @@ +@echo off + +REM Install NeoVim with winget, if not already present on the system +where nvim >nul 2>nul +if %errorlevel% neq 0 ( + winget install Neovim.Neovim -q +) + +REM Clone my dotfiles repo +set dotFilesRoot=%USERPROFILE%\dotfiles +if not exist "%dotFilesRoot%\." ( + git clone git@github.com:srdusr/dotfiles.git "%dotFilesRoot%" +) + +REM Link NeoVim configuration +set localConfiguration=%LOCALAPPDATA%\nvim +set dotfilesConfiguration=%dotFilesRoot%\.config\nvim + +if not exist "%localConfiguration%\." ( + mklink /D "%localConfiguration%" "%dotfilesConfiguration%" +) + +REM Clone Packer.nvim, if not already present on the system +set localPacker=%LOCALAPPDATA%\nvim-data\site\pack\packer\start\packer.nvim + +if not exist "%localPacker%\." ( + git clone https://github.com/wbthomason/packer.nvim "%localPacker%" +) + +REM Run the script by using this command in the same existing directory: win-nvim.bat + +@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://aka.ms/install-winget'))" +iex ((new-object net.webclient).DownloadString('https://aka.ms/install-winget')) +curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle + +powershell Add-AppxPackage -Path "winget-cli.appxbundle" + diff --git a/.local/bin/scripts/win-nvim.ps1 b/.local/bin/scripts/win-nvim.ps1 new file mode 100644 index 0000000..ca67755 --- /dev/null +++ b/.local/bin/scripts/win-nvim.ps1 @@ -0,0 +1,39 @@ +# Install NeoVim with winget, if not already present on the system +if (!(Get-Command nvim -ErrorAction SilentlyContinue)) { + winget install Neovim.Neovim +} + +# Clone my dotfiles repo +$dotFilesRoot = Join-Path $HOME "dotfiles" + +if (!(Test-Path $dotFilesRoot -PathType Container)) { + git clone https://github.com/srdusr/dotfiles.git $dotFilesRoot +} + +# Link NeoVim configuration +$localConfiguration = Join-Path $env:LOCALAPPDATA "nvim" +$dotfilesConfiguration = Join-Path $dotFilesRoot ".config" "nvim" + +if (!(Test-Path $localConfiguration -PathType Container)) { + Start-Process -FilePath "cmd.exe" -ArgumentList "/c mklink /D $localConfiguration $dotfilesConfiguration" -Verb runas +} + +# Clone Packer.nvim, if not already present on the system +$localPacker = Join-Path $env:LOCALAPPDATA "nvim-data" "site" "pack" "packer" "start" "packer.nvim" + +if (!(Test-Path $localPacker -PathType Container)) { + git clone https://github.com/wbthomason/packer.nvim $localPacker +} + +# To allow script execution, run the following command in PowerShell as an administrator: +# Set-ExecutionPolicy RemoteSigned +# Then run the script by using this command in the same existing directory: +# ./win-nvim.ps1 +#curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle +#powershell Add-AppxPackage -Path "winget-cli.appxbundle" +#Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) +#use `-y` or consider: choco feature enable -n allowGlobalConfirmation +#choco install git +#- Refresh the environment +#Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 +#refreshenv |
