Useful commands and scripts for the terminal.
Displays a random quote from a text file centered in the terminal.
#!/bin/bash
QUOTE_FILE="$HOME/.config/quote/quotes.txt"
if [[ ! -f "$QUOTE_FILE" ]]; then
echo "No quotes file found at $QUOTE_FILE"
exit 1
fi
quote=$(shuf -n 1 "$QUOTE_FILE")
cols=$(tput cols)
padding=$(( (cols - ${#quote}) / 2 ))
clear
for _ in {1..5}; do echo; done
printf "%*s\n" $((padding + ${#quote})) "$quote"
for _ in {1..5}; do echo; done
A script to list NCERT chapters for Classes 11 and 12, across Physics, Chemistry, and Mathematics.
#!/usr/bin/env zsh
# ncert - list NCERT chapters for Class 11 (-E) and Class 12 (-T)
# Subjects: -P Physics, -C Chemistry, -M Mathematics
# Usage examples:
# ncert -E -P # Class 11 Physics
# ncert -T -C # Class 12 Chemistry
# ---- colours ----
if [[ -t 1 ]]; then
BOLD="\e[1m"
RESET="\e[0m"
CYAN="\e[36m"
YELLOW="\e[33m"
GREEN="\e[32m"
BLUE="\e[34m"
else
BOLD=""; RESET=""; CYAN=""; YELLOW=""; GREEN=""; BLUE=""
fi
usage() {
printf "%b\n" "${BOLD}Usage:${RESET} ncert -E|-T -P|-C|-M"
printf " -E Class 11 (eleventh)\n -T Class 12 (twelfth)\n -P Physics\n -C Chemistry\n -M Mathematics\n"
printf "\nExamples:\n ncert -E -P # class 11 Physics\n ncert -T -M # class 12 Maths\n"
exit 1
}
# ---- parse options ----
grade=""
subject=""
err=0
while getopts "ETPCMetpcmh" opt; do
case $opt in
E|e)
if [[ -n $grade && $grade != "11" ]]; then printf "Error: specify only one of -E or -T\n"; err=1; fi
grade="11"
;;
T|t)
if [[ -n $grade && $grade != "12" ]]; then printf "Error: specify only one of -E or -T\n"; err=1; fi
grade="12"
;;
P|p)
if [[ -n $subject && $subject != "Physics" ]]; then printf "Error: specify only one subject flag (-P/-C/-M)\n"; err=1; fi
subject="Physics"
;;
C|c)
if [[ -n $subject && $subject != "Chemistry" ]]; then printf "Error: specify only one subject flag (-P/-C/-M)\n"; err=1; fi
subject="Chemistry"
;;
M|m)
if [[ -n $subject && $subject != "Mathematics" ]]; then printf "Error: specify only one subject flag (-P/-C/-M)\n"; err=1; fi
subject="Mathematics"
;;
h)
usage
;;
\?)
usage
;;
esac
done
if [[ $err -ne 0 ]]; then exit 2; fi
if [[ -z $grade || -z $subject ]]; then usage; fi
# ---- content blocks ----
case "$grade:$subject" in
"11:Physics")
content=$(cat <<'EOF'
Part 1: Mechanics
1. Physical world
2. Units and Measurements
3. Motion in a Straight Line
4. Motion in a Plane
5. Laws of Motion
6. Work, Energy and Power
7. System of Particles and Rotational Motion
8. Gravitation
9. Mechanical Properties of Solids
10. Mechanical Properties of Fluids
Part 2: Heat, Thermodynamics and Waves
11. Thermal Properties of Matter
12. Thermodynamics
13. Kinetic Theory of Gases
14. Oscillations
15. Waves
EOF
)
;;
"11:Chemistry")
content=$(cat <<'EOF'
Part 1: Physical Chemistry
1. Some Basic Concepts of Chemistry
2. Structure of Atom
3. Classification of Elements and Periodicity in Properties
4. Chemical Bonding and Molecular Structure
5. States of Matter: Gases and Liquids
6. Thermodynamics
7. Equilibrium
8. The Hydrogen Atom
Part 2: Inorganic & Organic Chemistry
9. The Periodic Table and Periodicity in Properties (continued)
10. The s-Block Elements (Alkali & Alkaline Earth Metals)
11. The p-Block Elements (Group 13 & 14)
12. Organic Chemistry — Some Basic Principles and Techniques
13. Hydrocarbons
14. The Chemistry of the p-Block (Group 15 & 16)
15. The Chemistry of the p-Block (Group 17 & 18)
16. Environmental Chemistry
EOF
)
;;
"11:Mathematics")
content=$(cat <<'EOF'
Part 1: Algebra, Calculus and Coordinate Geometry
1. Sets and Functions
2. Relations and Functions
3. Trigonometric Functions
4. Principle of Mathematical Induction
5. Complex Numbers and Quadratic Equations
6. Linear Inequalities
7. Permutations and Combinations
8. Binomial Theorem
9. Sequences and Series
Part 2: Geometry, Calculus and Statistics
10. Straight Lines
11. Conic Sections
12. Introduction to Three-Dimensional Geometry
13. Limits and Derivatives
14. Mathematical Reasoning
15. Statistics
16. Probability
EOF
)
;;
"12:Physics")
content=$(cat <<'EOF'
Part 1: Electrostatics, Current, Magnetism
1. Electrostatics
2. Current Electricity
3. Magnetic Effects of Current and Magnetism
4. Electromagnetic Induction
5. Alternating Currents
6. Electromagnetic Waves
Part 2: Optics, Modern Physics, and Electronics
7. Optics
8. Dual Nature of Matter and Radiation
9. Atoms
10. Nuclei
11. Semiconductor Electronics
EOF
)
;;
"12:Chemistry")
content=$(cat <<'EOF'
Part 1: Physical Chemistry
1. Solid State
2. Solutions
3. Electrochemistry
4. Chemical Kinetics
5. Surface Chemistry
Part 2: Inorganic & Organic Chemistry
6. General Principles and Inorganic Reactions
7. The p-Block Elements (Groups 13 & 14)
8. The p-Block Elements (Groups 15 & 16)
9. The d-Block Elements (Transition Elements)
10. The f-Block Elements (Lanthanides & Actinides)
11. Organic Chemistry — Some Basic Principles and Techniques
12. Hydrocarbons
13. Functional Groups: Alcohols, Phenols, Ethers
14. Functional Groups: Aldehydes, Ketones, Carboxylic Acids
15. Functional Groups: Amines
16. Biomolecules, Polymers, and Chemistry in Everyday Life
EOF
)
;;
"12:Mathematics")
content=$(cat <<'EOF'
Part 1: Algebra, Calculus, and Vectors
1. Relations and Functions
2. Inverse Trigonometric Functions
3. Matrices
4. Determinants
5. Continuity and Differentiability
6. Applications of Derivatives
7. Integrals
8. Applications of Integrals
Part 2: Vectors, 3D Geometry, Probability
9. Differential Equations
10. Vector Algebra
11. Three-Dimensional Geometry
12. Linear Programming
13. Probability
EOF
)
;;
*)
printf "Selection not implemented.\n"
exit 3
;;
esac
# ---- pretty print ----
printf "%b\n" "${BOLD}${CYAN}NCERT — Class ${grade} — ${subject}${RESET}"
printf "%b\n" "${BLUE}────────────────────────────────────────────────${RESET}"
# print content line-by-line with color for "Part" and numbers
while IFS= read -r line; do
if [[ -z $line ]]; then
printf "\n"
continue
fi
if [[ $line == Part* ]]; then
printf "%b\n" "${YELLOW}${line}${RESET}"
elif [[ $line =~ ^([0-9]+)\.(.*) ]]; then
num=${line%%.*}
rest=${line#*. }
printf "%b %b\n" "${GREEN}${num}.${RESET}" "${rest}"
else
printf "%b\n" "${line}"
fi
done <<< "$content"
printf "\n%b\n" "${BOLD}Tip:${RESET} run ${CYAN}ncert -E -P${RESET} (or add to \$PATH) to use quickly."
exit 0