aboutsummaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin')
-rw-r--r--.local/bin/scripts/check-updates.sh0
-rwxr-xr-x.local/bin/scripts/dotfiles.sh37
-rwxr-xr-x.local/bin/scripts/get_zle_keymap_select.sh13
-rw-r--r--.local/bin/scripts/install.sh19
-rwxr-xr-x.local/bin/scripts/qemu-helper.sh172
-rwxr-xr-x.local/bin/scripts/scratchpad91
-rw-r--r--.local/bin/scripts/win-nvim.bat37
-rw-r--r--.local/bin/scripts/win-nvim.ps139
8 files changed, 376 insertions, 32 deletions
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/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/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/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
index 2192236..1b3dfeb 100755
--- a/.local/bin/scripts/scratchpad
+++ b/.local/bin/scripts/scratchpad
@@ -1,41 +1,68 @@
-#!/usr/bin/bash
+#!/bin/bash
# Created By: srdusr
-# Created On: Wed 18 Jan 2023 11:15:22 PM CAT
-# Project: bspwm scratchpad with tmux session
-
-id=$(xdo id -n scratchpad);
-if [ -z "$id" ]; then
- wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash > /dev/null 2>&1 &
-else
- bspc node "$id" -g hidden -f
-fi
-
-#- - - - - - - - - -
-
+# Created On: Tue 07 Mar 2023 15:06:47 PM CAT
+# Project: Agnostic scratchpad/dropdown terminal that works on most window managers
-### Other 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
-#id=$(xdotool search --class scratchpad);
-#if [ -z "$id" ]; then
-# wezterm start --class scratchpad -e tmux new-session -A -s scratch -e bash > /dev/null 2>&1 &
-#else
-# if [ ! -f /tmp/scratchpad ]; then
-# touch /tmp/scratchpad && xdo hide "$id"
-# elif [ -f /tmp/scratchpad ]; then
-# rm /tmp/scratchpad && xdo show "$id"
-# fi
-#fi
+# 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
-### Alacritty alternative
-
-#if id="$(xdo id -N scratch)"
-# then bspc node "$id" -g hidden -f
-# else alacritty --class scratch,scratchpad -e tmux new-session -A -s scratch -e bash > /dev/null 2>&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