https://github.com/racoelhosilva/scripts
Collection of custom-made shell scripts to automate frequent operations on my Linux system both project and customization related
https://github.com/racoelhosilva/scripts
custom-scripts linux-scripts shell shell-scripts
Last synced: 9 days ago
JSON representation
Collection of custom-made shell scripts to automate frequent operations on my Linux system both project and customization related
- Host: GitHub
- URL: https://github.com/racoelhosilva/scripts
- Owner: racoelhosilva
- Created: 2023-09-24T13:42:30.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-06-21T08:47:55.000Z (7 months ago)
- Last Synced: 2025-06-21T09:32:11.181Z (7 months ago)
- Topics: custom-scripts, linux-scripts, shell, shell-scripts
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
#+TITLE: Custom Shell Scripts
#+AUTHOR: racoelhosilva
#+DESCRIPTION: Collection of custom made shell scripts for various linux operations
#+STARTUP: showeverything
Collection of custom made shell scripts for various linux operations
*** Table Of Contents :toc:
- [[#desktop-configuration][Desktop Configuration]]
- [[#alacritty-theme-changer][Alacritty Theme Changer]]
- [[#background-changer][Background Changer]]
- [[#leet-code][Leet Code]]
- [[#initialize-directory-structure][Initialize Directory Structure]]
- [[#create-a-problem-file][Create a Problem file]]
- [[#archive-the-file-and-update][Archive the File and Update]]
* Desktop Configuration
** Alacritty Theme Changer
Custom script to quickly change the alacritty theme.
Theme changes instantly. Themes should be placed inside "THEME_DIR".
Alacritty config file should import that same theme file.
*Commands:*
- alacritty-themer ls :: Lists possible theme options
- alacritty-themer :: Changes the current theme
#+BEGIN_SRC sh :tangle alacritty-themer :shebang "#!/bin/bash"
# Specify the alacritty config and theme directory
ALACRITTY_DIR="$HOME/.config/alacritty"
THEME_DIR="$HOME/.config/alacritty/themes"
# List theme options
if [ "$#" = 0 ] || [ "$1" = "ls" ]; then
echo "The current options are:"
ls "$THEME_DIR" | sed 's/\([a-z_0-9]*\).yaml/ - \1/g'
exit 0
fi
# Try to update the current theme
if ls $THEME_DIR | grep -w "$1.yaml" >/dev/null; then
sed -i 's|\('"$THEME_DIR"'/\)[a-z_0-9]*\(.yaml\)|\1'"$1"'\2|' "$ALACRITTY_DIR"/alacritty.yml
exit 0
else
echo "Couldn't change the theme. Please check spelling."
exit 1
fi
#+END_SRC
** Background Changer
Custom script to quickly change the background image.
This script assumes there is a single file in "WALLPAPER_SRC" which is the background sourced when booting the pc.
What it does is replacing that file with copy of an image chosen from the "WALLPAPER_DIR".
*Commands:*
- chbg ls :: Lists possible wallpaper options
- chbg :: Changes the wallpaper file and reloads it using 'feh'
#+BEGIN_SRC sh :tangle chbg :shebang "#!/bin/sh"
# Specify wallpaper directory and wallpaper sourced by applications
WALLPAPER_DIR="$HOME/.config/wallpaper/collection"
WALLPAPER_SRC="$HOME/.config/wallpaper/wallpaper.png"
# List wallpaper options
if [ "$#" = 0 ] || [ "$1" = "ls" ]; then
echo "The wallpaper options are:"
ls "$WALLPAPER_DIR" | sed 's/\([a-z_0-9]*\).png/ - \1/g'
exit 0
fi
# Try to update the current wallpaper
if ls $WALLPAPER_DIR | grep -w "$1.png" >/dev/null; then
cp "$WALLPAPER_DIR"/"$1".png "$WALLPAPER_SRC" 2>/dev/null
feh --bg-fill $WALLPAPER_SRC
exit 0
else
echo "Couldn't change the wallpaper. Please check spelling."
exit 1
fi
#+END_SRC
* Leet Code
** Initialize Directory Structure
#+BEGIN_SRC sh :tangle lc-init :shebang "#!/bin/bash"
if [ $# -gt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 initializes the directory structure for LeetCode problem solving"
echo "$0 also creates a README file to track the progress of solved problems"
exit 1
fi
TOPICS=(
"Arrays & Hashing"
"Backtracking"
"Binary Search"
"Binary Trees"
"Bit Manipulation"
"Dynamic Programming 1D"
"Dynamic Programming 2D"
"Graphs"
"Graphs Advanced"
"Greedy"
"Intervals"
"Linked Lists"
"Math & Geometry"
"Priority Queue"
"Sliding Window"
"Stack"
"Tries"
"Two Pointers"
)
DIFFICULTIES=(
"Easy"
"Medium"
"Hard"
)
for TOPIC in "${TOPICS[@]}"; do
for DIFFICULTY in "${DIFFICULTIES[@]}"; do
mkdir -p "$(pwd)"/"$TOPIC"/"$DIFFICULTY"
done
done
cat > README.md << EOF
# LeetCode Solutions/Analysis
> Collection of my solutions to [LeetCode](https://leetcode.com) problems
## Table of Contents
- [Progress Tracking](#progress-tracking)
- [Milestones](#milestones)
- [Useful Links](#useful-links)
## Progress Tracking
### Problems Solved
| Total | 0 |
|:---:|:---:|
#### Search By Topic
| Topic | Number |
|:---|---:|
EOF
for TOPIC in "${TOPICS[@]}"; do
echo "| $TOPIC | 0 |" >> README.md
done
cat >> README.md << EOF
#### Search By Difficulty
| Difficulty | Number |
|:---|---:|
EOF
for DIFFICULTY in "${DIFFICULTIES[@]}"; do
echo "| $DIFFICULTY | 0 |" >> README.md
done
cat >> README.md << EOF
## Milestones
| Date | Description |
|------|-------------|
| | |
## Useful Links
EOF
exit 0
#+END_SRC
** Create a Problem file
#+BEGIN_SRC sh :tangle lc-new :shebang "#!/bin/bash"
if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 creates a new file to solve a specific problem"
echo "$0 takes at least two parameters (number and name)"
echo "Usage: $0 "
exit 1
fi
NAME=${2// /}
cat > "$1"_"$NAME".cpp <<-EOF
/*
* Problem: $1
* Name: $2
* Difficulty: $3
* Topic:
* Link: https://leetcode.com/problems/
*/
#include
using namespace std;
EOF
exit 0
#+END_SRC
** Archive the File and Update
#+BEGIN_SRC sh :tangle lc-ar :shebang "#!/bin/bash"
if [ $# -gt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 archives a solve in the correct directory based on the Difficulty and Topic comments"
echo "$0 updates the README file, incrementing the corresponding values for the solved problems"
echo "$0 creates a commit with the file in the right position and a simple commit message"
exit 1
fi
NUMBER=$(head -n 2 <"$1" | tail -n 1 | cut -b 13-255)
NAME=$(head -n 3 <"$1" | tail -n 1 | cut -b 10-255)
DIFFICULTY=$(head -n 4 <"$1" | tail -n 1 | cut -b 16-255)
TOPIC=$(head -n 5 <"$1" | tail -n 1 | cut -b 11-255)
case "$DIFFICULTY" in
"Easy" | "Medium" | "Hard") ;;
*)
echo "ERROR! Incorrect Difficulty value!"
exit 1
;;
esac
case "$TOPIC" in
"Arrays & Hashing" | "Backtracking" | "Binary Search" | "Binary Trees" | "Bit Manipulation" | "Dynamic Programming 1D" | "Dynamic Programming 2D" | "Graphs" | "Graphs Advanced" | "Greedy" | "Intervals" | "Linked Lists" | "Math & Geometry" | "Priority Queue" | "Sliding Window" | "Stack" | "Tries" | "Two Pointers") ;;
*)
echo "ERROR! Incorrect Topic Name!"
exit 1;
;;
esac
mv "$1" "$TOPIC"/"$DIFFICULTY"
sed -ri 's/(\| )('"$TOPIC"'[[:space:]]\|[[:space:]])([0-9]+)( \|)/echo "\1\2$((\3+1))\4"/ge' README.md
sed -ri 's/(\| )('"$DIFFICULTY"'[[:space:]]\|[[:space:]])([0-9]+)( \|)/echo "\1\2$((\3+1))\4"/ge' README.md
sed -ri 's/(\| )(Total[[:space:]]\|[[:space:]])([0-9]+)( \|)/echo "\1\2$((\3+1))\4"/ge' README.md
git add "$TOPIC"/"$DIFFICULTY"/"$1" README.md
git commit -a -m "Solved problem $NUMBER: $NAME"
exit 0
#+END_SRC