Skip to content

Instantly share code, notes, and snippets.

View JaviLopezG's full-sized avatar
💭
🧑‍🌾 working on yups

Javi López G. JaviLopezG

💭
🧑‍🌾 working on yups
View GitHub Profile
@JaviLopezG
JaviLopezG / mytitle.sh
Created August 15, 2026 09:42
Change the terminal tab/window title with each command execution to locate it fast.
# ~/.bashrc - Update terminal title with current directory, last command, and hostname
_mytitle_get_cmd() {
local cmd="$1"
# Strip leading whitespace
cmd="${cmd#"${cmd%%[![:space:]]*}"}"
# Discard leading environment variable assignments (e.g., FOO=bar BAZ=123 cmd)
while [[ "$cmd" =~ ^[a-zA-Z_][a-zA-Z0-9_]*= ]]; do
@JaviLopezG
JaviLopezG / kk
Last active August 11, 2026 07:33
Command to make poop of any file.
#!/bin/sh
# kk: File backup, move, and undo utility using .kk extension
if [ "$1" = "-m" ]; then
shift
target="$1"
if [ -z "$target" ]; then
echo "Error: No file specified." >&2
exit 1
fi
@JaviLopezG
JaviLopezG / merge-pdfs-and-images.py
Created August 7, 2026 11:18
Script to merge all pdf and images in a single pdf file.
#!/bin/python
# merge-pdfs.py - Concatenates PDFs and images in subdirectories, adding the relative path as a header
import os
import fitz # PyMuPDF
def main():
root_dir = "."
output_file = "merged-files.pdf"
merged_pdf = fitz.open()
@JaviLopezG
JaviLopezG / buscar-comando.sh
Created August 7, 2026 11:14
TUI for fuzzy search of commands, to help when you can not remember the precise command.
IFS=':' read -ra ADDR <<< "$PATH"; (for dir in "${ADDR[@]}"; do [ -d "$dir" ] && ls -1 "$dir"; done) | sort -u | fzf
@JaviLopezG
JaviLopezG / backup.sh
Created August 7, 2026 10:51
Backup directory with rotation.
#!/bin/bash
# backup.sh - Daily backup script with GFS retention policy
SOURCE_DIR="/home/snowball/Trillian-bkp/home"
BACKUP_DIR="/home/snowball/Trillian-bkp/archive"
DATE=$(date +%Y-%m-%d)
BACKUP_FILE="${BACKUP_DIR}/backup_${DATE}.tar.gz"
mkdir -p "${BACKUP_DIR}"
@JaviLopezG
JaviLopezG / search-projects.sh
Created August 6, 2026 17:52
Script para buscar repositorios o carpetas con código en un árbol de directorios.
# search_projects.sh - Recursively search for git repos and small code directories, including inside archives.
#!/bin/bash
SEARCH_DIR="/mnt/externo"
# Awk script to parse file paths, count files per directory, and detect targets
AWK_SCRIPT='
{
filepath = $0
@JaviLopezG
JaviLopezG / .bashrc-prompt
Last active August 15, 2026 10:48
Prompt that shows if there was an error and the git branch if the directory is a repository
_update_prompt() {
local error=${GLOBAL_EXIT_CODE:-$?}
local c
local g
if [ $error -eq 0 ]; then
c="\[\e[1;92m\]🗹"
else
c="\[\e[1;31m\]🗵"
fi
@JaviLopezG
JaviLopezG / .bashrc-contextual-help
Last active January 13, 2026 21:27
Ctrl+SPACE to get help in bash
explain_current_line() {
local tokens=($READLINE_LINE)
local wrappers=("sudo" "su" "runuser" "chroot" "doas" "time" "watch" "timeout" "stdbuf" "nohup" "xargs" "exec" "env" "strace" "nice" "runcon" "setpriv" "bash" "sh")
for token in "${tokens[@]}"; do
if [[ "$token" == *"="* ]]; then continue; fi
local is_wrapper=false
for w in "${wrappers[@]}"; do
[[ "$token" == "$w" ]] && is_wrapper=true && break