Skip to content

Latest commit

 

History

History
265 lines (196 loc) · 6.53 KB

README.org

File metadata and controls

265 lines (196 loc) · 6.53 KB

Custom Shell Scripts

Collection of custom made shell scripts for various linux operations

Table Of Contents

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 <theme>
Changes the current theme
# 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

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 <image>
Changes the wallpaper file and reloads it using ‘feh’
# 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

Leet Code

Initialize Directory Structure

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

Create a Problem file

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 <problem_number> <problem_name> <difficulty> <topic>"
    exit 1
fi

NAME=${2// /}
cat > "$1"_"$NAME".cpp <<-EOF
/* 
 * Problem: $1 
 * Name: $2
 * Difficulty: $3
 * Topic: 
 * Link: https://leetcode.com/problems/
 */
 
#include <bits/stdc++.h>
using namespace std;
EOF

exit 0

Archive the File and Update

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