So, I’m in the process of remaking my diary website logic, going from 2024/01-02-Tue to 2024/01/02. That’s less useful while working with files, but is more useful to use with links, as -Tue becomes -tue, and even if I’d keep it, still not so useful to link. With the new logic, the links are much better now.

What I need to change is the logic of some scripts:

  • Weather (works automatically, each hour)
  • Nutrition (when I write eat into the terminal)
  • New Note (creates new note, when I press cmd+alt+F1)
  • Day (when I write day into the terminal)
  • Week (it does something automatically, and unfortunately, I don’t understand how and from where, as it looks like I should have disabled it).
  • Body (when I write body Shave or any other word into the terminal)
  • aliases in .my/shell for ranger

How I Renamed

I renamed the files semi-automatically. I put the directories into the months directories manually, and then I do rename them.

You can create a bash script that renames directories according to your specified pattern. Below is a script that takes a path as input and renames all directories inside it, keeping only the middle part of the original name.

Bash Script

#!/bin/bash

# Check if a path is provided
if [ -z "$1" ]; then
  echo "Usage: $0 <path>"
  exit 1
fi

# Get the path
DIR_PATH="$1"

# Check if the provided path is a directory
if [ ! -d "$DIR_PATH" ]; then
  echo "Error: $DIR_PATH is not a directory."
  exit 1
fi

# Iterate over all directories in the given path
for DIR in "$DIR_PATH"/*/; do
  # Extract the directory name (remove the trailing slash)
  DIR_NAME=$(basename "$DIR")
  
  # Extract the middle part using pattern matching
  NEW_NAME=$(echo "$DIR_NAME" | cut -d '-' -f 2)
  
  # Rename the directory
  mv "$DIR_PATH/$DIR_NAME" "$DIR_PATH/$NEW_NAME"
done

echo "Directories renamed successfully."

How to Use

  1. Save the script to a file, e.g., rename_dirs.sh.
  2. Make the script executable by running:
    chmod +x rename_dirs.sh
    
  3. Run the script with the desired directory path:
    ./rename_dirs.sh /path/to/your/directories
    

Explanation

  • DIR_PATH="$1": The path to the directory containing the directories to be renamed.
  • for DIR in "$DIR_PATH"/*/: Iterates over each directory in the given path.
  • basename "$DIR": Extracts the directory name from the path.
  • cut -d '-' -f 2: Extracts the middle part of the directory name.
  • mv "$DIR_PATH/$DIR_NAME" "$DIR_PATH/$NEW_NAME": Renames the directory.

This script will rename all directories inside the specified path, keeping only the middle part of their original names.