Commit for generation 124

This commit is contained in:
2024-09-27 18:38:21 -04:00
parent 1ce65eb1cc
commit 21e1bfe08e

View File

@@ -146,71 +146,48 @@ rc(){
} }
safe_rm() { safe_rm() {
dir="$@" for dir in "$@"; do
# Check if it's a file or directory
if [ -d "$dir" ] || [ -f "$dir" ]; then
# Get size of the directory or file
size=$(du -s "$dir" 2>/dev/null | awk '{print $1/1024}' | awk '{printf("%d\n", $1 + 0.5)}') size=$(du -s "$dir" 2>/dev/null | awk '{print $1/1024}' | awk '{printf("%d\n", $1 + 0.5)}')
files=$(ls -R "$dir" 2>/dev/null | wc -l)
# Count files (recursively if it's a directory)
files=$(find "$dir" | wc -l)
check=false check=false
is_file_or_dir="directory"
if [ "$files" -gt 20 ]; then
echo "There's a lot of stuff in here ($files files)."
check=true
fi
if [ "$size" -gt 1024 ]; then
is_file_or_dir=$([ -f "$dir" ] && echo 'file' || echo 'directory') is_file_or_dir=$([ -f "$dir" ] && echo 'file' || echo 'directory')
size_in_gb=$(echo "scale=2; $size / 1024" | bc -l)
echo "This $is_file_or_dir is kind of big ($size_in_gb GB)." # If there are many files, or the size is big, warn the user
if [ "$files" -gt 20 ]; then
echo "There's a lot of stuff in here ($files files) in '$dir'."
check=true check=true
fi fi
if [ "$size" -gt 1024 ]; then
size_in_gb=$(echo "scale=2; $size / 1024" | bc -l)
echo "This $is_file_or_dir is kind of big ($size_in_gb GB) in '$dir'."
check=true
fi
# Ask for confirmation only if necessary
if [ "$check" = true ]; then if [ "$check" = true ]; then
echo "Are you sure you want to remove this $is_file_or_dir? (y/n)" echo "Are you sure you want to remove this $is_file_or_dir '$dir'? (y/n)"
read -r confirm read -r confirm
fi fi
# Perform the removal if no checks or confirmation is "y"
if [ "$check" = false ] || [ "$confirm" = "y" ]; then if [ "$check" = false ] || [ "$confirm" = "y" ]; then
/run/current-system/sw/bin/rm -rfv "$dir" /run/current-system/sw/bin/rm -rfv "$dir"
else else
echo "Operation cancelled." echo "Operation cancelled for '$dir'."
fi fi
}
vimwiki() {
page="$@"
if [ -z "$page" ]; then
nvim ~/vimwiki/index.wiki
else else
nvim ~/vimwiki/$page.wiki echo "'$dir' does not exist or is not accessible."
fi fi
done
} }
nvim_find() {
nvim "$(fzf)"
}
change_kitty_theme() {
newtheme="$(find /home/pagedmov/dots/kitty/themes/themes/ -exec basename {} \; | sed 's/\.conf$//' | sed 's/\_/ /g' | fzf)"
builtin cd ~/dots/kitty/
themename=$newtheme
newtheme=$(echo "$newtheme" | sed 's/ /\_/g')
newtheme="./themes/themes/$newtheme.conf"
[ ! -f "$newtheme" ] && echo "Theme not found." && return
[ -e "$newtheme" ] && /usr/bin/rm ./theme.conf && echo "replacing theme"
ln -s "$newtheme" "./theme.conf"
kitty @ set-colors -a "$newtheme"
echo "Theme changed to $themename"
builtin cd $OLDPWD
}
window_title() {
echo -ne "\033]0;$1\007"
}
screengrab() {
if [ -n "$1" ]; then
name="$1.png"
else
name="$(date +%s | md5sum | cut -d ' ' -f 1).png"
fi
grimblast save area $name
}
nixswitch() { nixswitch() {
builtin cd "$HOME/sysflakes" builtin cd "$HOME/sysflakes"