Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidied tput formatting #125

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions opt/cs50/bin/code
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

# Formatting
bold=$(tput bold)
normal=$(tput sgr0)

# Check whether run with any options
options=false
for arg in "$@"; do
Expand All @@ -14,7 +18,7 @@ if [ "$options" = false ]; then

# If no arguments
if [ $# -eq 0 ]; then
read -p "Are you sure you want to run $(tput bold)code$(tput sgr0) without a filename? It would open a new tab. [y/N] " -r
read -p "Are you sure you want to run ${bold}code${normal} without a filename? It would open a new tab. [y/N] " -r
if [[ ! "${REPLY,,}" =~ ^y|yes$ ]]; then
exit 1
fi
Expand All @@ -28,7 +32,7 @@ if [ "$options" = false ]; then

# If a directory
if [ -d "$arg" ]; then
read -p "Are you sure you want to open $(tput bold)$arg$(tput sgr0)? It's a folder, not a file, so it would open in a new tab. [y/N] " -r
read -p "Are you sure you want to open ${bold}${arg}${normal}? It's a folder, not a file, so it would open in a new tab. [y/N] " -r
if [[ ! "${REPLY,,}" =~ ^y|yes$ ]]; then
exit 1
fi
Expand All @@ -39,31 +43,31 @@ if [ "$options" = false ]; then

# If first letter is capitalized but one of these languages
if [[ "$arg" =~ ^[A-Z].*\.(c|css|html|js|py)$ ]]; then
read -p "Are you sure you want to create $(tput bold)$arg$(tput sgr0)? Filenames aren't usually capitalized. [y/N] " -r
read -p "Are you sure you want to create ${bold}${arg}${normal}? Filenames aren't usually capitalized. [y/N] " -r
if [[ ! "${REPLY,,}" =~ ^y|yes$ ]]; then
exit 1
fi
fi

# If first letter is lowercase but Java
if [[ "$arg" =~ ^[a-z].*\.java$ ]]; then
read -p "Are you sure you want to create $(tput bold)$arg$(tput sgr0)? Filenames are usually capitalized. [y/N] " -r
read -p "Are you sure you want to create ${bold}${arg}${normal}? Filenames are usually capitalized. [y/N] " -r
if [[ ! "${REPLY,,}" =~ ^y|yes$ ]]; then
exit 1
fi
fi

# If file doesn't have an extension
if [[ ! "$arg" =~ \.[^.]+$ ]]; then
read -p "Are you sure you want to create $(tput bold)$arg$(tput sgr0)? Filenames usually have extensions. [y/N] " -r
read -p "Are you sure you want to create ${bold}${arg}${normal}? Filenames usually have extensions. [y/N] " -r
if [[ ! "${REPLY,,}" =~ ^y|yes$ ]]; then
exit 1
fi
fi

# If file extension is capitalized
if [[ "$arg" =~ \.[A-Z]+$ ]]; then
read -p "Are you sure you want to create $(tput bold)$arg$(tput sgr0)? File extensions aren't usually capitalized. [y/N] " -r
read -p "Are you sure you want to create ${bold}${arg}${normal}? File extensions aren't usually capitalized. [y/N] " -r
if [[ ! "${REPLY,,}" =~ ^y|yes$ ]]; then
exit 1
fi
Expand Down