initial dotfiles
This commit is contained in:
commit
45e5fe53d2
370 changed files with 25449 additions and 0 deletions
146
.config/yazi/scripts/create-archive.sh
Executable file
146
.config/yazi/scripts/create-archive.sh
Executable file
|
|
@ -0,0 +1,146 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Create archive script for Yazi
|
||||
# Compresses the current directory or selected items
|
||||
|
||||
# Get current directory name as default archive name
|
||||
current_dir=$(basename "$(pwd)")
|
||||
default_name="${current_dir}.tar.gz"
|
||||
|
||||
# Check if we're trying to archive something
|
||||
if [ -z "$(ls -A)" ]; then
|
||||
echo "Error: Current directory is empty"
|
||||
read -p "Press Enter to continue..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prompt for output directory
|
||||
printf "Output directory (default: current directory): "
|
||||
read -r output_dir
|
||||
|
||||
# Use current directory if empty
|
||||
if [ -z "$output_dir" ]; then
|
||||
output_dir="."
|
||||
else
|
||||
# Expand tilde and resolve path
|
||||
output_dir="${output_dir/#\~/$HOME}"
|
||||
# Create output directory if it doesn't exist
|
||||
if [ ! -d "$output_dir" ]; then
|
||||
printf "Directory '%s' doesn't exist. Create it? (Y/n): " "$output_dir"
|
||||
read -r create_confirm
|
||||
if [[ ! "$create_confirm" =~ ^[Nn]$ ]]; then
|
||||
mkdir -p "$output_dir"
|
||||
else
|
||||
echo "Archive creation cancelled"
|
||||
read -p "Press Enter to continue..."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Prompt for archive name
|
||||
printf "Archive name (default: %s): " "$default_name"
|
||||
printf "\nSupported formats: .zip, .tar.gz, .tar.bz2, .tar.xz, .7z\n"
|
||||
read -r archive_name
|
||||
|
||||
# Use default if empty
|
||||
if [ -z "$archive_name" ]; then
|
||||
archive_name="$default_name"
|
||||
fi
|
||||
|
||||
# Construct full archive path
|
||||
archive_path="$output_dir/$archive_name"
|
||||
|
||||
# Check if archive already exists
|
||||
if [ -f "$archive_path" ]; then
|
||||
printf "Warning: Archive '%s' already exists! Overwrite? (y/N): " "$archive_path"
|
||||
read -r confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo "Archive creation cancelled"
|
||||
read -p "Press Enter to continue..."
|
||||
exit 0
|
||||
fi
|
||||
rm -f "$archive_path"
|
||||
fi
|
||||
|
||||
# Prompt for what to include
|
||||
printf "Archive entire current directory? (Y/n): "
|
||||
read -r choice
|
||||
|
||||
if [[ "$choice" =~ ^[Nn]$ ]]; then
|
||||
printf "Enter space-separated files/folders to archive: "
|
||||
read -r items
|
||||
if [ -z "$items" ]; then
|
||||
echo "Error: No items specified"
|
||||
read -p "Press Enter to continue..."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Archive everything in current directory
|
||||
items="."
|
||||
fi
|
||||
|
||||
# Create archive based on extension
|
||||
case "$archive_name" in
|
||||
*.tar.gz | *.tgz)
|
||||
if [ "$items" = "." ]; then
|
||||
# Archive contents of current directory
|
||||
parent_dir=$(dirname "$(pwd)")
|
||||
current_name=$(basename "$(pwd)")
|
||||
tar -czf "$archive_path" -C "$parent_dir" "$current_name"
|
||||
else
|
||||
tar -czf "$archive_path" $items
|
||||
fi
|
||||
;;
|
||||
*.tar.bz2 | *.tbz2)
|
||||
if [ "$items" = "." ]; then
|
||||
parent_dir=$(dirname "$(pwd)")
|
||||
current_name=$(basename "$(pwd)")
|
||||
tar -cjf "$archive_path" -C "$parent_dir" "$current_name"
|
||||
else
|
||||
tar -cjf "$archive_path" $items
|
||||
fi
|
||||
;;
|
||||
*.tar.xz | *.txz)
|
||||
if [ "$items" = "." ]; then
|
||||
parent_dir=$(dirname "$(pwd)")
|
||||
current_name=$(basename "$(pwd)")
|
||||
tar -cJf "$archive_path" -C "$parent_dir" "$current_name"
|
||||
else
|
||||
tar -cJf "$archive_path" $items
|
||||
fi
|
||||
;;
|
||||
*.zip)
|
||||
if [ "$items" = "." ]; then
|
||||
parent_dir=$(dirname "$(pwd)")
|
||||
current_name=$(basename "$(pwd)")
|
||||
(cd "$parent_dir" && zip -qr "$archive_path" "$current_name")
|
||||
else
|
||||
zip -qr "$archive_path" $items
|
||||
fi
|
||||
;;
|
||||
*.7z)
|
||||
if [ "$items" = "." ]; then
|
||||
parent_dir=$(dirname "$(pwd)")
|
||||
current_name=$(basename "$(pwd)")
|
||||
(cd "$parent_dir" && 7z a -r "$archive_path" "$current_name" >/dev/null)
|
||||
else
|
||||
7z a -r "$archive_path" $items >/dev/null
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unsupported archive format"
|
||||
echo "Please use: .zip, .tar.gz, .tar.bz2, .tar.xz, or .7z"
|
||||
read -p "Press Enter to continue..."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully created archive: $archive_path"
|
||||
read -p "Press Enter to continue..."
|
||||
else
|
||||
echo "Error: Archive creation failed"
|
||||
read -p "Press Enter to continue..."
|
||||
exit 1
|
||||
fi
|
||||
68
.config/yazi/scripts/extract-archive.sh
Executable file
68
.config/yazi/scripts/extract-archive.sh
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Extract archive script for Yazi
|
||||
# Supports: .zip, .tar.gz, .tgz, .tar.bz2, .tbz2, .tar.xz, .txz, .tar, .rar, .7z
|
||||
|
||||
archive="$1"
|
||||
|
||||
# Check if file exists and is a regular file
|
||||
if [ ! -f "$archive" ]; then
|
||||
echo "Error: Not a valid file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the base name without extension for default extraction directory
|
||||
basename="${archive%.*}"
|
||||
# Handle double extensions like .tar.gz
|
||||
if [[ "$archive" =~ \.(tar\.gz|tar\.bz2|tar\.xz)$ ]]; then
|
||||
basename="${archive%.*.*}"
|
||||
fi
|
||||
|
||||
# Prompt for extraction directory
|
||||
printf "Extract to directory (default: %s): " "$basename"
|
||||
read -r extract_dir
|
||||
|
||||
# Use default if empty
|
||||
if [ -z "$extract_dir" ]; then
|
||||
extract_dir="$basename"
|
||||
fi
|
||||
|
||||
# Create extraction directory if it doesn't exist
|
||||
mkdir -p "$extract_dir"
|
||||
|
||||
# Extract based on file extension
|
||||
case "$archive" in
|
||||
*.zip)
|
||||
unzip -q "$archive" -d "$extract_dir"
|
||||
;;
|
||||
*.tar.gz | *.tgz)
|
||||
tar -xzf "$archive" -C "$extract_dir"
|
||||
;;
|
||||
*.tar.bz2 | *.tbz2)
|
||||
tar -xjf "$archive" -C "$extract_dir"
|
||||
;;
|
||||
*.tar.xz | *.txz)
|
||||
tar -xJf "$archive" -C "$extract_dir"
|
||||
;;
|
||||
*.tar)
|
||||
tar -xf "$archive" -C "$extract_dir"
|
||||
;;
|
||||
*.rar)
|
||||
unrar x "$archive" "$extract_dir/"
|
||||
;;
|
||||
*.7z)
|
||||
7z x "$archive" -o"$extract_dir"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unsupported archive format"
|
||||
rmdir "$extract_dir" 2>/dev/null
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully extracted to: $extract_dir"
|
||||
else
|
||||
echo "Error: Extraction failed"
|
||||
exit 1
|
||||
fi
|
||||
30
.config/yazi/scripts/safe-delete.sh
Executable file
30
.config/yazi/scripts/safe-delete.sh
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
BACKUP_DIR="/drives/rei/backup"
|
||||
|
||||
# Hard-delete whitelist (exact real paths)
|
||||
ALLOW_DELETE=(
|
||||
"$HOME/.cache"
|
||||
"/drives/rei/backup"
|
||||
)
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
for item in "$@"; do
|
||||
real_item="$(realpath "$item" 2>/dev/null)"
|
||||
|
||||
# Check if the item is in the hard-delete whitelist
|
||||
for allowed in "${ALLOW_DELETE[@]}"; do
|
||||
real_allowed="$(realpath "$allowed" 2>/dev/null)"
|
||||
if [[ "$real_item" == "$real_allowed"* ]]; then
|
||||
rm -rf -- "$item"
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
|
||||
# Otherwise move to backup with timestamp
|
||||
base="$(basename "$item")"
|
||||
ts="$(date +%Y%m%d_%H%M%S)"
|
||||
|
||||
mv -- "$item" "$BACKUP_DIR/$base-$ts"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue