Created
March 6, 2024 05:34
-
-
Save gaurangrshah/7b206c792d9ee6a7ff4179e993831027 to your computer and use it in GitHub Desktop.
.sh scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the number of arguments is correct | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <file_path> <alias_name>" | |
exit 1 | |
fi | |
# Get the arguments | |
file_path="$1" | |
alias_name="$2" | |
# Create a new file with the contents from the clipboard | |
pbpaste > "$file_path" | |
# Set executable permissions on the file | |
chmod +x "$file_path" | |
# Add an alias entry to the .zshrc config | |
echo "alias $alias_name=\"$file_path\"" >> ~/.zshrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the number of arguments is correct | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <gist_url> <file_path>" | |
exit 1 | |
fi | |
# Get the arguments | |
user_gistid="$1" # username/gistid | |
file_path="$2" | |
# Extract the directory path and file name from the provided file path | |
destination_dir=$(dirname "$file_path") | |
file_name=$(basename "$file_path") | |
# Check and create the destination directory if needed | |
if [[ ! -d "$destination_dir" ]]; then | |
mkdir -p "$destination_dir" | |
echo "Created directory: $destination_dir" | |
fi | |
# Construct the complete URL, including the file name | |
file_url="https://gist.githubusercontent.com/$user_gistid/raw/$file_name" | |
# Check and create the file if needed (ensures it's empty if it doesn't exist) | |
touch "$destination_dir/$file_name" | |
# Download and append to the file | |
curl -s "$file_url" >> "$destination_dir/$file_name" | |
echo "File downloaded and saved to: $destination_dir/$file_name" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to duplicate a file | |
duplicate_file() { | |
local source_file=$1 | |
local destination_file=$2 | |
cp "$source_file" "$destination_file" | |
echo "File duplicated successfully!" | |
} | |
# Function to duplicate a directory | |
duplicate_directory() { | |
local source_directory=$1 | |
local destination_directory=$2 | |
cp -R "$source_directory" "$destination_directory" | |
echo "Directory duplicated successfully!" | |
} | |
# Check if the -R flag is provided | |
if [[ $1 == "-R" ]]; then | |
# Check if a directory path is provided | |
if [[ -d $2 ]]; then | |
source_directory=$2 | |
destination_directory=$3 | |
duplicate_directory "$source_directory" "$destination_directory" | |
else | |
echo "Invalid directory path!" | |
exit 1 | |
fi | |
else | |
# Check if a file path is provided | |
if [[ -f $1 ]]; then | |
source_file=$1 | |
destination_file=$2 | |
duplicate_file "$source_file" "$destination_file" | |
else | |
echo "Invalid file path!" | |
exit 1 | |
fi | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will download the contents of a GitHub repo | |
# and place them in a local directory. | |
# | |
# Usage: | |
# download-repo.sh <repo> <output-path> <nested-path> | |
# | |
# Example: | |
# download-repo.sh wattenberger/kumiko ./kumiko-assets | |
# public/assets | |
# | |
# You'll get rate-limited by GitHub, so create a PAT here: | |
# https://github.com/settings/tokens | |
# This will also let you download from private repos. | |
GITHUB_TOKEN="YOUR_TOKEN_HERE" | |
repo=$1 | |
# split repo name to username and repository name | |
repo_name=`echo $repo | cut -d/ -f2` | |
repo_user=`echo $repo | cut -d/ -f1` | |
output_path=$2 | |
nested_path=$3 | |
# if no output_path is given, use the repo name | |
if [ -z "$output_path" ]; then | |
output_path="./${repo_name}" | |
fi | |
url="https://api.github.com/repos/${repo}/git/trees/master?recursive=1" | |
# fetch repo data | |
full_tree_string=`curl -s -H "Authorization: token | |
${GITHUB_TOKEN}" "${url}"` | |
# get paths where type is not tree | |
paths=`echo ${full_tree_string} | jq -r '.tree[] | | |
select(.type != "tree") | .path'` | |
# filter out lines that don't start with nested_path and | |
# remove nested_path prefix | |
paths=`echo "${paths}" | grep -E "^${nested_path}" | sed | |
"s|^${nested_path}||g"` | |
number_of_paths=`echo "${paths}" | wc -l | sed "s/^[ | |
\t]*//"` | |
echo "Found ${number_of_paths} files, fetching contents..." | |
mkdir -p "${output_path}/" | |
set -o noclobber | |
# fetch contents for each line in paths | |
for path in ${paths}; do | |
echo "Fetching ${path}..." | |
url="https://raw.githubusercontent.com/${repo}/master/${nested_path}${path}" | |
path_without_filename=$(dirname "/${path}") | |
full_path="${output_path}${path_without_filename}" | |
mkdir -p "${full_path}/" | |
# download and save file from url | |
curl -s -H "Authorization: token ${GITHUB_TOKEN}" | |
"${url}" > "${output_path}/${path}" | |
done | |
echo "All set! 🌈" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if package.json exists | |
if [ ! -f "package.json" ]; then | |
echo "Error: package.json not found in the current directory." | |
exit 1 | |
fi | |
# Check if "next", "react", and "react-dom" are listed as dependencies | |
if ! grep -q '"next"\|react\|react-dom' package.json; then | |
echo "Error: 'next', 'react', or 'react-dom' are not listed as dependencies in package.json." | |
exit 1 | |
fi | |
# Function to prompt the user for yes/no answer | |
confirm_step() { | |
while true; do | |
read -p "$1 (y/n): " yn | |
case $yn in | |
[Yy]* ) return 0;; | |
[Nn]* ) return 1;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
} | |
# append .env to .gitignore | |
if confirm_step "Do you want to append .env to .gitignore?"; then | |
echo '.env' >> .gitignore | |
fi | |
# Install dependencies | |
if confirm_step "Do you want to add prettier as a dependency with eslint & tailwind configs?"; then | |
pnpm add -D prettier eslint-config-prettier prettier-plugin-tailwindcss | |
fi | |
# Create eslintrc.json | |
if confirm_step "Do you want to add prettier to eslintrc.json?"; then | |
echo ' | |
{ | |
"extends": ["next/core-web-vitals", "prettier"] | |
} | |
' > .eslintrc.json | |
fi | |
# Create .prettierrc | |
if confirm_step "Do you want to create .prettierrc?"; then | |
echo ' | |
{ | |
"trailingComma": "es5", | |
"semi": true, | |
"tabWidth": 2, | |
"singleQuote": true, | |
"jsxSingleQuote": false, | |
"plugins": ["prettier-plugin-tailwindcss"], | |
"pluginSearchDirs": false | |
} | |
' > .prettierrc.json | |
fi | |
if confirm_step "Do you want to create .prettierignore?"; then | |
echo ' | |
/node_modules | |
/.next/ | |
' > .prettierignore | |
fi | |
if confirm_step "Do you want create a vscode settings file with prettier configs?"; then | |
mkdir -p .vscode && echo '{ "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true }' > .vscode/settings.json | |
fi | |
# Use pnpm exec for shadcn-ui init | |
if confirm_step "Do you want to initialize shadcn-ui?"; then | |
pnpm dlx shadcn-ui@latest init | |
fi | |
# Append to app/globals.css | |
if confirm_step "Do you want to append styles to app/globals.css?"; then | |
echo ' | |
/* Flexbox height fix */ | |
html, | |
body, | |
:root { | |
height: 100%; | |
} | |
/* Prefer box-sizing */ | |
*, | |
*::before, | |
*::after { | |
box-sizing: border-box; | |
} | |
.text-balance { | |
text-align: balance; | |
} | |
' >> app/globals.css | |
fi | |
if confirm_step "Do you want to add email dev to package.json?"; then | |
jq '.scripts += { | |
"email": "email dev", | |
}' package.json > package.json.tmp && mv package.json.tmp package.json | |
fi | |
if confirm_step "Do you want to add additional db scripts to package.json?"; then | |
jq '.scripts += { | |
"db:sync": "drizzle-kit generate:sqlite drizzle-kit push:sqlite", | |
"db:seed": "pnpm dlx tsx lib/db/seed.ts", | |
"turso:dev": "turso dev", | |
"turso:dev:persist": "turso dev --db-file ./.dev/teacup.db","seed": "prisma", | |
}' package.json > package.json.tmp && mv package.json.tmp package.json | |
fi | |
if confirm_step "Do you want to add format and format:fix scripts to package.json?"; then | |
jq '.scripts += { | |
"format": "prettier --check --plugin=prettier-plugin-tailwindcss --ignore-path .gitignore .", | |
"format:fix": "prettier --write --plugin=prettier-plugin-tailwindcss --ignore-path .gitignore ." | |
}' package.json > package.json.tmp && mv package.json.tmp package.json | |
fi | |
echo "Project scaffolded successfully!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install dependencies | |
pnpm add -D prettier eslint-config-prettier prettier-plugin-tailwindcss | |
# Create eslintrc.json | |
echo ' | |
{ | |
"extends": ["next/core-web-vitals", "prettier"] | |
} | |
' > .eslintrc.json | |
# Create .prettierrc | |
echo ' | |
{ | |
"trailingComma": "es5", | |
"semi": true, | |
"tabWidth": 2, | |
"singleQuote": true, | |
"jsxSingleQuote": true, | |
"plugins": ["prettier-plugin-tailwindcss"], | |
"printWidth": 120 | |
} | |
' > .prettierrc | |
# Use pnpm exec for shadcn-ui init | |
pnpm exec shadcn-ui@latest init | |
# NOTE: this must occur after shadcn is installed otherwise styles will be overwritten | |
echo ' | |
/* Flexbox height fix */ | |
html, | |
body, | |
:root { | |
height: 100%; | |
} | |
/* Prefer box-sizing */ | |
*, | |
*::before, | |
*::after { | |
box-sizing: border-box; | |
} | |
.text-balance { | |
text-align: balance; | |
} | |
' >> app/globals.css | |
echo "Project scaffolded successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment