changed ext of scripts files
This commit is contained in:
parent
b9a3eef410
commit
ce385066d1
24 changed files with 1018 additions and 958 deletions
|
|
@ -1,35 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set_fzf_theme() {
|
||||
local appearance="$1"
|
||||
|
||||
# Detect the current system appearance (Light or Dark mode) for Linux and macOS
|
||||
if [[ -z "$appearance" ]]; then
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
appearance=$(defaults read -g AppleInterfaceStyle 2>/dev/null)
|
||||
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux (assuming GNOME)
|
||||
appearance=$(gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null)
|
||||
else
|
||||
# Default to Dark mode if the system is not recognized
|
||||
appearance="Dark"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set FZF theme based on appearance
|
||||
if [[ $appearance == *"Dark"* || -n "$TMUX" ]]; then
|
||||
# Monokai (Dark Theme) with slight adjustments
|
||||
FZF_DEFAULT_OPTS="--color=bg+:#272822,bg:#272822,spinner:#ff669d,hl:#66d9ee,fg:#f8f8f2,header:#ff669d,info:#66d9ee,pointer:#a6e22e,marker:#a6e22e,fg+:#e8e8e3,prompt:#66d9ee,hl+:#66d9ee"
|
||||
else
|
||||
# Solarized Light with better contrast for readability
|
||||
FZF_DEFAULT_OPTS="--color=bg+:#fdf6e3,bg:#fdf6e3,spinner:#d33682,hl:#cb4b16,fg:#586e75,header:#d33682,info:#268bd2,pointer:#859900,marker:#859900,fg+:#073642,prompt:#268bd2,hl+:#cb4b16"
|
||||
fi
|
||||
|
||||
echo "$FZF_DEFAULT_OPTS"
|
||||
}
|
||||
|
||||
# Call the function if executed directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
set_fzf_theme "$1"
|
||||
fi
|
||||
35
scripts/fzf_theme.sh
Executable file
35
scripts/fzf_theme.sh
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set_fzf_theme() {
|
||||
local appearance="$1"
|
||||
|
||||
# Detect the current system appearance (Light or Dark mode) for Linux and macOS
|
||||
if [[ -z "$appearance" ]]; then
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
appearance=$(defaults read -g AppleInterfaceStyle 2>/dev/null)
|
||||
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux (assuming GNOME)
|
||||
appearance=$(gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null)
|
||||
else
|
||||
# Default to Dark mode if the system is not recognized
|
||||
appearance="Dark"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set FZF theme based on appearance
|
||||
if [[ $appearance == *"Dark"* || -n "$TMUX" ]]; then
|
||||
# Monokai (Dark Theme) with slight adjustments
|
||||
FZF_DEFAULT_OPTS="--color=bg+:#272822,bg:#272822,spinner:#ff669d,hl:#66d9ee,fg:#f8f8f2,header:#ff669d,info:#66d9ee,pointer:#a6e22e,marker:#a6e22e,fg+:#e8e8e3,prompt:#66d9ee,hl+:#66d9ee"
|
||||
else
|
||||
# Solarized Light with better contrast for readability
|
||||
FZF_DEFAULT_OPTS="--color=bg+:#fdf6e3,bg:#fdf6e3,spinner:#d33682,hl:#cb4b16,fg:#586e75,header:#d33682,info:#268bd2,pointer:#859900,marker:#859900,fg+:#002b36,prompt:#eee8d5,hl+:#b58900"
|
||||
fi
|
||||
|
||||
echo "$FZF_DEFAULT_OPTS"
|
||||
}
|
||||
|
||||
# Call the function if executed directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
set_fzf_theme "$1"
|
||||
fi
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default settings
|
||||
DATASET_DIR="data/raw" # Directory to store downloaded datasets
|
||||
NOTEBOOK_DIR="notebooks" # Directory to store downloaded notebooks
|
||||
COMMIT_MESSAGE="Added dataset or notebook" # Default commit message
|
||||
VERBOSE=0 # Default verbosity flag
|
||||
|
||||
# Usage function
|
||||
usage() {
|
||||
echo "Usage: $0 [options]"
|
||||
echo " -d, --dataset Kaggle dataset name (e.g., 'username/dataset-name') to download"
|
||||
echo " -n, --notebook Kaggle notebook URL suffix (e.g., 'username/notebook-name') to download"
|
||||
echo " -s, --submit Notebook file to submit to a competition"
|
||||
echo " -c, --competition Competition name for notebook submission"
|
||||
echo " -g, --git Flag to add and commit changes to Git after download or submission"
|
||||
echo " -v, --verbose Enable verbose output"
|
||||
echo " -h, --help Display this help message"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Parse command-line arguments
|
||||
COMMIT_FLAG=0
|
||||
DATASET_NAME=""
|
||||
NOTEBOOK_NAME=""
|
||||
NOTEBOOK_FILE=""
|
||||
COMPETITION_NAME=""
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-d | --dataset)
|
||||
DATASET_NAME="$2"
|
||||
shift
|
||||
;;
|
||||
-n | --notebook)
|
||||
NOTEBOOK_NAME="$2"
|
||||
shift
|
||||
;;
|
||||
-s | --submit)
|
||||
NOTEBOOK_FILE="$2"
|
||||
shift
|
||||
;;
|
||||
-c | --competition)
|
||||
COMPETITION_NAME="$2"
|
||||
shift
|
||||
;;
|
||||
-g | --git) COMMIT_FLAG=1 ;;
|
||||
-v | --verbose) VERBOSE=1 ;;
|
||||
-h | --help) usage ;; # Call usage function for help
|
||||
*) usage ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Extract Kaggle credentials from kaggle.json
|
||||
if ! KAGGLE_USERNAME=$(jq -r .username ~/.kaggle/kaggle.json) || ! KAGGLE_KEY=$(jq -r .key ~/.kaggle/kaggle.json); then
|
||||
echo "Failed to retrieve Kaggle credentials from kaggle.json."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if credentials were successfully extracted
|
||||
if [[ -z "$KAGGLE_USERNAME" || -z "$KAGGLE_KEY" ]]; then
|
||||
echo "Kaggle credentials are empty. Please check your kaggle.json file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to echo messages if verbosity is enabled
|
||||
verbose_echo() {
|
||||
if [[ $VERBOSE -eq 1 ]]; then
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Download dataset
|
||||
if [[ -n "$DATASET_NAME" ]]; then
|
||||
# Create the dataset directory if it doesn't exist
|
||||
mkdir -p "$DATASET_DIR"
|
||||
|
||||
# Download the dataset using curl
|
||||
verbose_echo "Downloading dataset: $DATASET_NAME to $DATASET_DIR"
|
||||
if ! curl -L -o "${DATASET_DIR}/dataset.zip" \
|
||||
-u "$KAGGLE_USERNAME:$KAGGLE_KEY" \
|
||||
"https://www.kaggle.com/api/v1/datasets/download/$DATASET_NAME"; then
|
||||
echo "Failed to download dataset: $DATASET_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Unzip the dataset and remove the zip file
|
||||
verbose_echo "Unzipping dataset..."
|
||||
if ! unzip -o "${DATASET_DIR}/dataset.zip" -d "$DATASET_DIR"; then
|
||||
echo "Failed to unzip dataset."
|
||||
exit 1
|
||||
fi
|
||||
rm "${DATASET_DIR}/dataset.zip"
|
||||
|
||||
# Git add and commit if the flag is set
|
||||
if [[ $COMMIT_FLAG -eq 1 ]]; then
|
||||
if ! git add "$DATASET_DIR"; then
|
||||
echo "Failed to add dataset to Git."
|
||||
exit 1
|
||||
fi
|
||||
if ! git commit -m "$COMMIT_MESSAGE: Dataset $DATASET_NAME"; then
|
||||
echo "Failed to commit dataset to Git."
|
||||
exit 1
|
||||
fi
|
||||
verbose_echo "Committed dataset $DATASET_NAME to Git."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Download notebook
|
||||
if [[ -n "$NOTEBOOK_NAME" ]]; then
|
||||
# Create the notebook directory if it doesn't exist
|
||||
mkdir -p "$NOTEBOOK_DIR"
|
||||
|
||||
# Download the notebook using curl
|
||||
verbose_echo "Downloading notebook: $NOTEBOOK_NAME to $NOTEBOOK_DIR"
|
||||
if ! curl -L -o "${NOTEBOOK_DIR}/${NOTEBOOK_NAME##*/}.ipynb" \
|
||||
-u "$KAGGLE_USERNAME:$KAGGLE_KEY" \
|
||||
"https://www.kaggle.com/api/v1/kernels/source/$NOTEBOOK_NAME"; then
|
||||
echo "Failed to download notebook: $NOTEBOOK_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Git add and commit if the flag is set
|
||||
if [[ $COMMIT_FLAG -eq 1 ]]; then
|
||||
if ! git add "$NOTEBOOK_DIR"; then
|
||||
echo "Failed to add notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
if ! git commit -m "$COMMIT_MESSAGE: Notebook $NOTEBOOK_NAME"; then
|
||||
echo "Failed to commit notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
verbose_echo "Committed notebook $NOTEBOOK_NAME to Git."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Submit a notebook to a Kaggle competition
|
||||
if [[ -n "$NOTEBOOK_FILE" && -n "$COMPETITION_NAME" ]]; then
|
||||
verbose_echo "Submitting notebook: $NOTEBOOK_FILE to competition $COMPETITION_NAME"
|
||||
|
||||
# Submit the notebook
|
||||
if ! curl -L -X POST \
|
||||
-F "file=@${NOTEBOOK_FILE}" \
|
||||
-u "$KAGGLE_USERNAME:$KAGGLE_KEY" \
|
||||
"https://www.kaggle.com/api/v1/competitions/submissions/upload/$COMPETITION_NAME"; then
|
||||
echo "Notebook submission failed."
|
||||
exit 1
|
||||
else
|
||||
echo "Notebook submitted successfully!"
|
||||
|
||||
# Git add and commit if the flag is set
|
||||
if [[ $COMMIT_FLAG -eq 1 ]]; then
|
||||
if ! git add "$NOTEBOOK_FILE"; then
|
||||
echo "Failed to add submitted notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
if ! git commit -m "$COMMIT_MESSAGE: Submitted notebook $NOTEBOOK_FILE to $COMPETITION_NAME"; then
|
||||
echo "Failed to commit submitted notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
verbose_echo "Committed submitted notebook $NOTEBOOK_FILE to Git."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# If no operation was specified
|
||||
if [[ -z "$DATASET_NAME" && -z "$NOTEBOOK_NAME" && -z "$NOTEBOOK_FILE" ]]; then
|
||||
echo "No operation specified. Please provide a dataset, notebook, or submission to process."
|
||||
usage
|
||||
fi
|
||||
171
scripts/kaggle_manager.sh
Executable file
171
scripts/kaggle_manager.sh
Executable file
|
|
@ -0,0 +1,171 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default settings
|
||||
DATASET_DIR="data/raw" # Directory to store downloaded datasets
|
||||
NOTEBOOK_DIR="notebooks" # Directory to store downloaded notebooks
|
||||
COMMIT_MESSAGE="Added dataset or notebook" # Default commit message
|
||||
VERBOSE=0 # Default verbosity flag
|
||||
|
||||
# Usage function
|
||||
usage() {
|
||||
echo "Usage: $0 [options]"
|
||||
echo " -d, --dataset Kaggle dataset name (e.g., 'username/dataset-name') to download"
|
||||
echo " -n, --notebook Kaggle notebook URL suffix (e.g., 'username/notebook-name') to download"
|
||||
echo " -s, --submit Notebook file to submit to a competition"
|
||||
echo " -c, --competition Competition name for notebook submission"
|
||||
echo " -g, --git Flag to add and commit changes to Git after download or submission"
|
||||
echo " -v, --verbose Enable verbose output"
|
||||
echo " -h, --help Display this help message"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Parse command-line arguments
|
||||
COMMIT_FLAG=0
|
||||
DATASET_NAME=""
|
||||
NOTEBOOK_NAME=""
|
||||
NOTEBOOK_FILE=""
|
||||
COMPETITION_NAME=""
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-d | --dataset)
|
||||
DATASET_NAME="$2"
|
||||
shift
|
||||
;;
|
||||
-n | --notebook)
|
||||
NOTEBOOK_NAME="$2"
|
||||
shift
|
||||
;;
|
||||
-s | --submit)
|
||||
NOTEBOOK_FILE="$2"
|
||||
shift
|
||||
;;
|
||||
-c | --competition)
|
||||
COMPETITION_NAME="$2"
|
||||
shift
|
||||
;;
|
||||
-g | --git) COMMIT_FLAG=1 ;;
|
||||
-v | --verbose) VERBOSE=1 ;;
|
||||
-h | --help) usage ;; # Call usage function for help
|
||||
*) usage ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Extract Kaggle credentials from kaggle.json
|
||||
if ! KAGGLE_USERNAME=$(jq -r .username ~/.kaggle/kaggle.json) || ! KAGGLE_KEY=$(jq -r .key ~/.kaggle/kaggle.json); then
|
||||
echo "Failed to retrieve Kaggle credentials from kaggle.json."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if credentials were successfully extracted
|
||||
if [[ -z "$KAGGLE_USERNAME" || -z "$KAGGLE_KEY" ]]; then
|
||||
echo "Kaggle credentials are empty. Please check your kaggle.json file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to echo messages if verbosity is enabled
|
||||
verbose_echo() {
|
||||
if [[ $VERBOSE -eq 1 ]]; then
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Download dataset
|
||||
if [[ -n "$DATASET_NAME" ]]; then
|
||||
# Create the dataset directory if it doesn't exist
|
||||
mkdir -p "$DATASET_DIR"
|
||||
|
||||
# Download the dataset using curl
|
||||
verbose_echo "Downloading dataset: $DATASET_NAME to $DATASET_DIR"
|
||||
if ! curl -L -o "${DATASET_DIR}/dataset.zip" \
|
||||
-u "$KAGGLE_USERNAME:$KAGGLE_KEY" \
|
||||
"https://www.kaggle.com/api/v1/datasets/download/$DATASET_NAME"; then
|
||||
echo "Failed to download dataset: $DATASET_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Unzip the dataset and remove the zip file
|
||||
verbose_echo "Unzipping dataset..."
|
||||
if ! unzip -o "${DATASET_DIR}/dataset.zip" -d "$DATASET_DIR"; then
|
||||
echo "Failed to unzip dataset."
|
||||
exit 1
|
||||
fi
|
||||
rm "${DATASET_DIR}/dataset.zip"
|
||||
|
||||
# Git add and commit if the flag is set
|
||||
if [[ $COMMIT_FLAG -eq 1 ]]; then
|
||||
if ! git add "$DATASET_DIR"; then
|
||||
echo "Failed to add dataset to Git."
|
||||
exit 1
|
||||
fi
|
||||
if ! git commit -m "$COMMIT_MESSAGE: Dataset $DATASET_NAME"; then
|
||||
echo "Failed to commit dataset to Git."
|
||||
exit 1
|
||||
fi
|
||||
verbose_echo "Committed dataset $DATASET_NAME to Git."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Download notebook
|
||||
if [[ -n "$NOTEBOOK_NAME" ]]; then
|
||||
# Create the notebook directory if it doesn't exist
|
||||
mkdir -p "$NOTEBOOK_DIR"
|
||||
|
||||
# Download the notebook using curl
|
||||
verbose_echo "Downloading notebook: $NOTEBOOK_NAME to $NOTEBOOK_DIR"
|
||||
if ! curl -L -o "${NOTEBOOK_DIR}/${NOTEBOOK_NAME##*/}.ipynb" \
|
||||
-u "$KAGGLE_USERNAME:$KAGGLE_KEY" \
|
||||
"https://www.kaggle.com/api/v1/kernels/source/$NOTEBOOK_NAME"; then
|
||||
echo "Failed to download notebook: $NOTEBOOK_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Git add and commit if the flag is set
|
||||
if [[ $COMMIT_FLAG -eq 1 ]]; then
|
||||
if ! git add "$NOTEBOOK_DIR"; then
|
||||
echo "Failed to add notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
if ! git commit -m "$COMMIT_MESSAGE: Notebook $NOTEBOOK_NAME"; then
|
||||
echo "Failed to commit notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
verbose_echo "Committed notebook $NOTEBOOK_NAME to Git."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Submit a notebook to a Kaggle competition
|
||||
if [[ -n "$NOTEBOOK_FILE" && -n "$COMPETITION_NAME" ]]; then
|
||||
verbose_echo "Submitting notebook: $NOTEBOOK_FILE to competition $COMPETITION_NAME"
|
||||
|
||||
# Submit the notebook
|
||||
if ! curl -L -X POST \
|
||||
-F "file=@${NOTEBOOK_FILE}" \
|
||||
-u "$KAGGLE_USERNAME:$KAGGLE_KEY" \
|
||||
"https://www.kaggle.com/api/v1/competitions/submissions/upload/$COMPETITION_NAME"; then
|
||||
echo "Notebook submission failed."
|
||||
exit 1
|
||||
else
|
||||
echo "Notebook submitted successfully!"
|
||||
|
||||
# Git add and commit if the flag is set
|
||||
if [[ $COMMIT_FLAG -eq 1 ]]; then
|
||||
if ! git add "$NOTEBOOK_FILE"; then
|
||||
echo "Failed to add submitted notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
if ! git commit -m "$COMMIT_MESSAGE: Submitted notebook $NOTEBOOK_FILE to $COMPETITION_NAME"; then
|
||||
echo "Failed to commit submitted notebook to Git."
|
||||
exit 1
|
||||
fi
|
||||
verbose_echo "Committed submitted notebook $NOTEBOOK_FILE to Git."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# If no operation was specified
|
||||
if [[ -z "$DATASET_NAME" && -z "$NOTEBOOK_NAME" && -z "$NOTEBOOK_FILE" ]]; then
|
||||
echo "No operation specified. Please provide a dataset, notebook, or submission to process."
|
||||
usage
|
||||
fi
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Define constants
|
||||
FZF_THEME="$HOME/.local/bin/scripts/fzf_theme"
|
||||
LS_OPTS="-la --color=always"
|
||||
|
||||
# List of directories to include in the search
|
||||
INCLUDED_DIRS=(
|
||||
"$HOME/.dotfiles"
|
||||
"$HOME/Documents"
|
||||
"$HOME/.local/bin"
|
||||
"$HOME/Google Drive/My Drive"
|
||||
)
|
||||
|
||||
# Function to handle cleanup on keyboard interrupt or stop
|
||||
cleanup() {
|
||||
echo "Interrupt detected. Cleaning up..."
|
||||
|
||||
if pgrep -x tmux >/dev/null && [[ -n "$TMUX" ]]; then
|
||||
local original_session
|
||||
original_session=$(tmux list-sessions -F "#{session_name}" | tail -n 1)
|
||||
tmux switch-client -t "$original_session"
|
||||
elif command -v wezterm >/dev/null && wezterm --version | grep -q "wezterm"; then
|
||||
local tab_id
|
||||
tab_id=$(wezterm cli list | tail -n 1 | awk '{print $2}')
|
||||
wezterm cli activate-tab --tab-id "$tab_id"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Trap the SIGINT (Ctrl+C) and SIGTSTP (Ctrl+Z) signals to handle cleanup
|
||||
trap cleanup SIGINT SIGTSTP
|
||||
|
||||
# Function to find and deduplicate directories
|
||||
find_directories() {
|
||||
local finder="$1"
|
||||
local include_params=("${@:2}")
|
||||
|
||||
# Use a single call to find directories, optimizing the process
|
||||
"$finder" -H --min-depth 1 --max-depth 3 --type d . "${include_params[@]}" | sort -u
|
||||
}
|
||||
|
||||
# Function to search and select directories using a fuzzy finder
|
||||
search_dirs() {
|
||||
local finder="$1"
|
||||
local fuzzy_finder="$2"
|
||||
local include_params=("${INCLUDED_DIRS[@]}")
|
||||
|
||||
local all_dirs
|
||||
all_dirs=$(find_directories "$finder" "${include_params[@]}")
|
||||
|
||||
local selected
|
||||
selected=$(
|
||||
echo "$all_dirs" | "$fuzzy_finder" "$($FZF_THEME)" --cycle \
|
||||
--preview "if command -v eza >/dev/null; then eza $LS_OPTS --group-directories-first {}; else ls $LS_OPTS {}; fi"
|
||||
)
|
||||
|
||||
if [ -n "$selected" ]; then
|
||||
echo "$selected"
|
||||
else
|
||||
echo "No directory selected. Exiting." >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to handle terminal multiplexer or tab management
|
||||
handle_terminal() {
|
||||
local selected="$1"
|
||||
local selected_name
|
||||
|
||||
selected_name=$(basename "$selected" | tr '.' '_')
|
||||
local full_path="${selected/#\~/$HOME}"
|
||||
|
||||
if pgrep -x tmux >/dev/null && [[ -n "$TMUX" ]]; then
|
||||
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
|
||||
tmux new-session -ds "$selected_name" -c "$selected"
|
||||
fi
|
||||
tmux switch-client -t "$selected_name"
|
||||
elif command -v wezterm >/dev/null && wezterm --version | grep -q "wezterm"; then
|
||||
local workspace_exists
|
||||
workspace_exists=$(wezterm cli list-workspaces | grep -w "$selected_name")
|
||||
|
||||
if [[ -z $workspace_exists ]]; then
|
||||
wezterm cli create-workspace --name "$selected_name" --cwd "$full_path" # Create a new workspace
|
||||
fi
|
||||
wezterm cli switch-to-workspace --name "$selected_name"
|
||||
else
|
||||
echo "Warning: No terminal multiplexer detected (tmux or WezTerm)." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function to coordinate the script
|
||||
main() {
|
||||
local selected
|
||||
|
||||
if command -v sk >/dev/null && sk --version >/dev/null 2>&1; then
|
||||
selected=$(search_dirs "fd" "sk")
|
||||
elif command -v fzf >/dev/null && fzf --version >/dev/null 2>&1; then
|
||||
selected=$(search_dirs "fd" "fzf")
|
||||
else
|
||||
echo "Warning: No fuzzy finder program detected (fzf or sk). Install one or use command line arguments." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$selected" ]]; then
|
||||
handle_terminal "$selected"
|
||||
fi
|
||||
}
|
||||
|
||||
# Execute the main function
|
||||
main
|
||||
113
scripts/sessionizer.sh
Executable file
113
scripts/sessionizer.sh
Executable file
|
|
@ -0,0 +1,113 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Define constants
|
||||
FZF_THEME="$HOME/.local/bin/scripts/fzf_theme"
|
||||
LS_OPTS="-la --color=always"
|
||||
|
||||
# List of directories to include in the search
|
||||
INCLUDED_DIRS=(
|
||||
"$HOME/.dotfiles"
|
||||
"$HOME/Documents"
|
||||
"$HOME/.local/bin"
|
||||
"$HOME/Google Drive/My Drive"
|
||||
)
|
||||
|
||||
# Function to handle cleanup on keyboard interrupt or stop
|
||||
cleanup() {
|
||||
echo "Interrupt detected. Cleaning up..."
|
||||
|
||||
if pgrep -x tmux >/dev/null && [[ -n "$TMUX" ]]; then
|
||||
local original_session
|
||||
original_session=$(tmux list-sessions -F "#{session_name}" | tail -n 1)
|
||||
tmux switch-client -t "$original_session"
|
||||
elif command -v wezterm >/dev/null && wezterm --version | grep -q "wezterm"; then
|
||||
local tab_id
|
||||
tab_id=$(wezterm cli list | tail -n 1 | awk '{print $2}')
|
||||
wezterm cli activate-tab --tab-id "$tab_id"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Trap the SIGINT (Ctrl+C) and SIGTSTP (Ctrl+Z) signals to handle cleanup
|
||||
trap cleanup SIGINT SIGTSTP
|
||||
|
||||
# Function to find and deduplicate directories
|
||||
find_directories() {
|
||||
local finder="$1"
|
||||
local include_params=("${@:2}")
|
||||
|
||||
# Use a single call to find directories, optimizing the process
|
||||
"$finder" -H --min-depth 1 --max-depth 3 --type d . "${include_params[@]}" | sort -u
|
||||
}
|
||||
|
||||
# Function to search and select directories using a fuzzy finder
|
||||
search_dirs() {
|
||||
local finder="$1"
|
||||
local fuzzy_finder="$2"
|
||||
local include_params=("${INCLUDED_DIRS[@]}")
|
||||
|
||||
local all_dirs
|
||||
all_dirs=$(find_directories "$finder" "${include_params[@]}")
|
||||
|
||||
local selected
|
||||
selected=$(
|
||||
echo "$all_dirs" | "$fuzzy_finder" "$($FZF_THEME)" --cycle \
|
||||
--preview "if command -v eza >/dev/null; then eza $LS_OPTS --group-directories-first {}; else ls $LS_OPTS {}; fi"
|
||||
)
|
||||
|
||||
if [ -n "$selected" ]; then
|
||||
echo "$selected"
|
||||
else
|
||||
echo "No directory selected. Exiting." >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to handle terminal multiplexer or tab management
|
||||
handle_terminal() {
|
||||
local selected="$1"
|
||||
local selected_name
|
||||
|
||||
selected_name=$(basename "$selected" | tr '.' '_')
|
||||
local full_path="${selected/#\~/$HOME}"
|
||||
|
||||
if pgrep -x tmux >/dev/null && [[ -n "$TMUX" ]]; then
|
||||
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
|
||||
tmux new-session -ds "$selected_name" -c "$selected"
|
||||
fi
|
||||
tmux switch-client -t "$selected_name"
|
||||
elif command -v wezterm >/dev/null && wezterm --version | grep -q "wezterm"; then
|
||||
local workspace_exists
|
||||
workspace_exists=$(wezterm cli list-workspaces | grep -w "$selected_name")
|
||||
|
||||
if [[ -z $workspace_exists ]]; then
|
||||
wezterm cli create-workspace --name "$selected_name" --cwd "$full_path" # Create a new workspace
|
||||
fi
|
||||
wezterm cli switch-to-workspace --name "$selected_name"
|
||||
else
|
||||
echo "Warning: No terminal multiplexer detected (tmux or WezTerm)." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function to coordinate the script
|
||||
main() {
|
||||
local selected
|
||||
|
||||
if command -v sk >/dev/null && sk --version >/dev/null 2>&1; then
|
||||
selected=$(search_dirs "fd" "sk")
|
||||
elif command -v fzf >/dev/null && fzf --version >/dev/null 2>&1; then
|
||||
selected=$(search_dirs "fd" "fzf")
|
||||
else
|
||||
echo "Warning: No fuzzy finder program detected (fzf or sk). Install one or use command line arguments." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$selected" ]]; then
|
||||
handle_terminal "$selected"
|
||||
fi
|
||||
}
|
||||
|
||||
# Execute the main function
|
||||
main
|
||||
|
|
@ -1,332 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Function to check if a command is available
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to perform package manager updates and upgrades
|
||||
update_and_upgrade() {
|
||||
local package_manager=$1
|
||||
case $package_manager in
|
||||
"brew")
|
||||
echo "Updating and upgrading Homebrew..."
|
||||
brew update && brew upgrade
|
||||
;;
|
||||
"apt-get")
|
||||
echo "Updating package list and upgrading..."
|
||||
sudo apt-get update && sudo apt-get upgrade -y
|
||||
;;
|
||||
"yum")
|
||||
echo "Updating package list and upgrading..."
|
||||
sudo yum check-update && sudo yum update -y
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported package manager: $package_manager"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to perform cleanup tasks
|
||||
cleanup() {
|
||||
local package_manager=$1
|
||||
case $package_manager in
|
||||
"brew")
|
||||
echo "Cleaning up..."
|
||||
brew cleanup
|
||||
;;
|
||||
"apt-get")
|
||||
echo "Cleaning up..."
|
||||
sudo apt-get autoremove -y && sudo apt-get clean
|
||||
;;
|
||||
"yum")
|
||||
echo "Cleaning up..."
|
||||
sudo yum clean all
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to install a single dependency
|
||||
install_dependency() {
|
||||
local package_manager=$1
|
||||
local dependency=$2
|
||||
case $package_manager in
|
||||
"brew")
|
||||
brew install "$dependency"
|
||||
;;
|
||||
"apt-get")
|
||||
sudo apt-get install -y "$dependency"
|
||||
;;
|
||||
"yum")
|
||||
sudo yum install -y "$dependency"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to install dependencies based on the package manager
|
||||
install_dependencies() {
|
||||
local package_manager=$1
|
||||
shift
|
||||
|
||||
update_and_upgrade "$package_manager"
|
||||
|
||||
echo "Installing dependencies..."
|
||||
for dependency in "$@"; do
|
||||
echo "Installing $dependency..."
|
||||
install_dependency "$package_manager" "$dependency"
|
||||
INSTALLED_DEPENDENCIES+=("$dependency ($package_manager)")
|
||||
done
|
||||
|
||||
cleanup "$package_manager"
|
||||
}
|
||||
|
||||
# Function to install dependencies from a list
|
||||
install_dependency_list() {
|
||||
local package_manager=$1
|
||||
local dependencies_file=$2
|
||||
|
||||
update_and_upgrade "$package_manager"
|
||||
|
||||
echo "Installing dependencies from list..."
|
||||
while IFS=, read -r dependency link_or_path; do
|
||||
if [ -n "$link_or_path" ]; then
|
||||
echo "Installing $dependency from $link_or_path"
|
||||
if [[ "$link_or_path" =~ ^http ]]; then
|
||||
case $package_manager in
|
||||
"brew") brew install "$link_or_path" ;;
|
||||
"apt-get") wget "$link_or_path" -O /tmp/"$dependency".deb && sudo dpkg -i /tmp/"$dependency".deb ;;
|
||||
"yum") wget "$link_or_path" -O /tmp/"$dependency".rpm && sudo yum localinstall -y /tmp/"$dependency".rpm ;;
|
||||
esac
|
||||
else
|
||||
case $package_manager in
|
||||
"brew") brew install "$link_or_path" ;;
|
||||
"apt-get") sudo dpkg -i "$link_or_path" ;;
|
||||
"yum") sudo yum localinstall -y "$link_or_path" ;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "Installing $dependency from default repository"
|
||||
install_dependency "$package_manager" "$dependency"
|
||||
fi
|
||||
INSTALLED_DEPENDENCIES+=("$dependency ($package_manager)")
|
||||
done <"$dependencies_file"
|
||||
|
||||
cleanup "$package_manager"
|
||||
}
|
||||
|
||||
# Function to determine the package manager and set it globally
|
||||
set_package_manager() {
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
if ! command_exists brew; then
|
||||
echo "Homebrew is not installed. Installing Homebrew..."
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
PACKAGE_MANAGER="brew"
|
||||
elif [ "$(uname)" == "Linux" ]; then
|
||||
if command_exists apt-get; then
|
||||
PACKAGE_MANAGER="apt-get"
|
||||
elif command_exists yum; then
|
||||
PACKAGE_MANAGER="yum"
|
||||
else
|
||||
echo "Unsupported package manager. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Unsupported operating system $(uname). Exiting."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to handle auto-updates for Homebrew
|
||||
handle_auto_update() {
|
||||
if [ "$ENABLE_AUTO_UPDATE" == true ] && [ "$PACKAGE_MANAGER" == "brew" ]; then
|
||||
if command_exists brew; then
|
||||
brew autoupdate --start --upgrade --cleanup
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install and configure zsh
|
||||
install_and_configure_shell() {
|
||||
if ! command_exists zsh; then
|
||||
install_dependencies "$PACKAGE_MANAGER" zsh
|
||||
# Replaced by zinit in .zshrc
|
||||
# if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
||||
# git clone https://github.com/ohmyzsh/ohmyzsh.git "$HOME/.oh-my-zsh"
|
||||
# fi
|
||||
if [ "$SHELL" != "$(command -v zsh)" ]; then
|
||||
chsh -s "$(command -v zsh)"
|
||||
fi
|
||||
|
||||
exec zsh -l
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install essential tools
|
||||
install_essential_tools() {
|
||||
if ! command_exists curl; then
|
||||
install_dependencies "$PACKAGE_MANAGER" curl
|
||||
fi
|
||||
if ! command_exists unzip; then
|
||||
install_dependencies "$PACKAGE_MANAGER" unzip
|
||||
fi
|
||||
if ! command_exists git; then
|
||||
install_dependencies "$PACKAGE_MANAGER" git fd ripgrep fzf tree
|
||||
fi
|
||||
if ! command_exists nvim; then
|
||||
install_dependencies "$PACKAGE_MANAGER" neovim
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install Go
|
||||
install_go() {
|
||||
case $PACKAGE_MANAGER in
|
||||
"brew") install_dependencies "$PACKAGE_MANAGER" go ;;
|
||||
"apt-get" | "yum") install_dependencies "$PACKAGE_MANAGER" golang ;;
|
||||
*)
|
||||
echo "Unsupported package manager: $PACKAGE_MANAGER"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to install Python and Poetry
|
||||
install_python() {
|
||||
# Check if "global" argument is passed
|
||||
GLOBAL_INSTALL=true
|
||||
if [[ "$1" == "local" ]]; then
|
||||
GLOBAL_INSTALL=false
|
||||
fi
|
||||
|
||||
# Install pyenv if it's not already installed
|
||||
if ! command -v pyenv >/dev/null 2>&1; then
|
||||
echo "Installing pyenv..."
|
||||
curl https://pyenv.run | bash
|
||||
|
||||
# Set up pyenv in the current shell session
|
||||
export PATH="$HOME/.pyenv/bin:$PATH"
|
||||
eval "$(pyenv init --path)"
|
||||
eval "$(pyenv init -)"
|
||||
eval "$(pyenv virtualenv-init -)"
|
||||
fi
|
||||
|
||||
# Ensure Python 3.7+ is installed via pyenv
|
||||
REQUIRED_VERSION="3.7.0"
|
||||
# Function to check if the installed Python version is at least the required version
|
||||
check_python_version() {
|
||||
INSTALLED_VERSION=$(python -c "import sys; print('{}.{}'.format(sys.version_info.major, sys.version_info.minor))")
|
||||
|
||||
if [[ $(printf '%s\n' "$REQUIRED_VERSION" "$INSTALLED_VERSION" | sort -V | head -n 1) == "$REQUIRED_VERSION" ]]; then
|
||||
echo "Python version $INSTALLED_VERSION is installed and meets the requirement."
|
||||
else
|
||||
echo "Python version is less than $REQUIRED_VERSION. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_python_version
|
||||
|
||||
# Set Python version globally or locally
|
||||
if [[ "$GLOBAL_INSTALL" == true ]]; then
|
||||
echo "Setting Python $REQUIRED_VERSION as the global version..."
|
||||
pyenv global "$REQUIRED_VERSION"
|
||||
else
|
||||
echo "Setting Python $REQUIRED_VERSION as the local version..."
|
||||
pyenv local "$REQUIRED_VERSION"
|
||||
fi
|
||||
|
||||
# Rehash pyenv to make the new version available
|
||||
pyenv rehash
|
||||
|
||||
# Install Poetry using the pyenv-installed Python
|
||||
echo "Installing Poetry..."
|
||||
curl -sSL https://install.python-poetry.org | python3 -
|
||||
}
|
||||
|
||||
# Function to install all programming languages
|
||||
install_programming_languages() {
|
||||
install_go
|
||||
install_python global # Pass "global" as an argument to set Python globally
|
||||
}
|
||||
|
||||
# Function to install MesloLGS Nerd Font
|
||||
install_meslolgs_nerd_font() {
|
||||
if [ ! -f "$HOME/.local/share/fonts/MesloLGS NF Regular.ttf" ]; then
|
||||
mkdir -p ~/.local/share/fonts
|
||||
cd ~/.local/share/fonts || return
|
||||
curl -fLo "MesloLGS NF Regular.ttf" https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip
|
||||
unzip Meslo.zip -d meslo
|
||||
mv meslo/*.ttf ~/.local/share/fonts/
|
||||
rm -rf Meslo.zip meslo
|
||||
fc-cache -f -v
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to display installed dependencies
|
||||
show_installed_dependencies() {
|
||||
echo "Installed dependencies:"
|
||||
for dependency in "${INSTALLED_DEPENDENCIES[@]}"; do
|
||||
echo " - $dependency"
|
||||
done
|
||||
}
|
||||
|
||||
# Function to start shell
|
||||
start_shell() {
|
||||
if command -v zsh &>/dev/null; then
|
||||
zsh
|
||||
elif command -v bash &>/dev/null; then
|
||||
bash
|
||||
elif command -v fish &>/dev/null; then
|
||||
fish
|
||||
else
|
||||
echo "Neither zsh nor bash is installed. Please install one of them manually."
|
||||
fi
|
||||
}
|
||||
|
||||
# Default values for flags
|
||||
ENABLE_AUTO_UPDATE=true
|
||||
DEPENDENCIES_FILE=""
|
||||
ADDITIONAL_DEPENDENCIES=()
|
||||
INSTALLED_DEPENDENCIES=()
|
||||
|
||||
# Parse command-line arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-a | --disable-auto-update)
|
||||
ENABLE_AUTO_UPDATE=false
|
||||
shift
|
||||
;;
|
||||
-d | --dependencies)
|
||||
DEPENDENCIES_FILE="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
ADDITIONAL_DEPENDENCIES+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Main script execution
|
||||
set_package_manager
|
||||
handle_auto_update
|
||||
install_essential_tools
|
||||
install_and_configure_shell
|
||||
install_programming_languages
|
||||
|
||||
# Install MesloLGS Nerd Font
|
||||
install_meslolgs_nerd_font
|
||||
|
||||
# Install dependencies from provided file if specified
|
||||
if [ -n "$DEPENDENCIES_FILE" ]; then
|
||||
install_dependency_list "$PACKAGE_MANAGER" "$DEPENDENCIES_FILE"
|
||||
fi
|
||||
|
||||
# Install additional dependencies provided as arguments
|
||||
if [ "${#ADDITIONAL_DEPENDENCIES[@]}" -gt 0 ]; then
|
||||
install_dependencies "$PACKAGE_MANAGER" "${ADDITIONAL_DEPENDENCIES[@]}"
|
||||
fi
|
||||
|
||||
show_installed_dependencies
|
||||
start_shell
|
||||
362
scripts/setup_dev_env.sh
Executable file
362
scripts/setup_dev_env.sh
Executable file
|
|
@ -0,0 +1,362 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
DOTFILES_REPO="git@github.com:jfraeys/dotfiles.git"
|
||||
DOTFILES_DIR="$HOME/.dotfiles"
|
||||
|
||||
# Function to check if a command is available
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to perform package manager updates and upgrades
|
||||
update_and_upgrade() {
|
||||
local package_manager=$1
|
||||
case $package_manager in
|
||||
"brew")
|
||||
echo "Updating and upgrading Homebrew..."
|
||||
brew update && brew upgrade
|
||||
;;
|
||||
"apt-get")
|
||||
echo "Updating package list and upgrading..."
|
||||
sudo apt-get update && sudo apt-get upgrade -y
|
||||
;;
|
||||
"yum")
|
||||
echo "Updating package list and upgrading..."
|
||||
sudo yum check-update && sudo yum update -y
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported package manager: $package_manager"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to perform cleanup tasks
|
||||
cleanup() {
|
||||
local package_manager=$1
|
||||
case $package_manager in
|
||||
"brew")
|
||||
echo "Cleaning up..."
|
||||
brew cleanup
|
||||
;;
|
||||
"apt-get")
|
||||
echo "Cleaning up..."
|
||||
sudo apt-get autoremove -y && sudo apt-get clean
|
||||
;;
|
||||
"yum")
|
||||
echo "Cleaning up..."
|
||||
sudo yum clean all
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to install a single dependency
|
||||
install_dependency() {
|
||||
local package_manager=$1
|
||||
local dependency=$2
|
||||
case $package_manager in
|
||||
"brew")
|
||||
brew install "$dependency"
|
||||
;;
|
||||
"apt-get")
|
||||
sudo apt-get install -y "$dependency"
|
||||
;;
|
||||
"yum")
|
||||
sudo yum install -y "$dependency"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to install dependencies based on the package manager
|
||||
install_dependencies() {
|
||||
local package_manager=$1
|
||||
shift
|
||||
|
||||
update_and_upgrade "$package_manager"
|
||||
|
||||
echo "Installing dependencies..."
|
||||
for dependency in "$@"; do
|
||||
echo "Installing $dependency..."
|
||||
install_dependency "$package_manager" "$dependency"
|
||||
INSTALLED_DEPENDENCIES+=("$dependency ($package_manager)")
|
||||
done
|
||||
|
||||
cleanup "$package_manager"
|
||||
}
|
||||
|
||||
# Function to install dependencies from a list
|
||||
install_dependency_list() {
|
||||
local package_manager=$1
|
||||
local dependencies_file=$2
|
||||
|
||||
update_and_upgrade "$package_manager"
|
||||
|
||||
echo "Installing dependencies from list..."
|
||||
while IFS=, read -r dependency link_or_path; do
|
||||
if [ -n "$link_or_path" ]; then
|
||||
echo "Installing $dependency from $link_or_path"
|
||||
if [[ "$link_or_path" =~ ^http ]]; then
|
||||
case $package_manager in
|
||||
"brew") brew install "$link_or_path" ;;
|
||||
"apt-get") wget "$link_or_path" -O /tmp/"$dependency".deb && sudo dpkg -i /tmp/"$dependency".deb ;;
|
||||
"yum") wget "$link_or_path" -O /tmp/"$dependency".rpm && sudo yum localinstall -y /tmp/"$dependency".rpm ;;
|
||||
esac
|
||||
else
|
||||
case $package_manager in
|
||||
"brew") brew install "$link_or_path" ;;
|
||||
"apt-get") sudo dpkg -i "$link_or_path" ;;
|
||||
"yum") sudo yum localinstall -y "$link_or_path" ;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "Installing $dependency from default repository"
|
||||
install_dependency "$package_manager" "$dependency"
|
||||
fi
|
||||
INSTALLED_DEPENDENCIES+=("$dependency ($package_manager)")
|
||||
done <"$dependencies_file"
|
||||
|
||||
cleanup "$package_manager"
|
||||
}
|
||||
|
||||
# Function to determine the package manager and set it globally
|
||||
set_package_manager() {
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
if ! command_exists brew; then
|
||||
echo "Homebrew is not installed. Installing Homebrew..."
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
PACKAGE_MANAGER="brew"
|
||||
elif [ "$(uname)" == "Linux" ]; then
|
||||
if command_exists apt-get; then
|
||||
PACKAGE_MANAGER="apt-get"
|
||||
elif command_exists yum; then
|
||||
PACKAGE_MANAGER="yum"
|
||||
else
|
||||
echo "Unsupported package manager. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Unsupported operating system $(uname). Exiting."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to handle auto-updates for Homebrew
|
||||
handle_auto_update() {
|
||||
if [ "$ENABLE_AUTO_UPDATE" == true ] && [ "$PACKAGE_MANAGER" == "brew" ]; then
|
||||
if command_exists brew; then
|
||||
brew autoupdate --start --upgrade --cleanup
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Setup Mac OS dock
|
||||
setup_macos_dock() {
|
||||
if [ "$(uname)" != "Darwin" ]; then
|
||||
echo "This function is only supported on macOS. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
defaults write com.apple.dock autohide -bool true
|
||||
defaults write com.apple.dock tilesize -int 36
|
||||
defaults write com.apple.dock largesize -int 64
|
||||
defaults write com.apple.dock magnification -bool true
|
||||
defaults write com.apple.dock largesize -int 64
|
||||
defaults write com.apple.dock orientation -string "left"
|
||||
defaults write com.apple.dock mineffect -string "scale"
|
||||
default
|
||||
}
|
||||
|
||||
# Function to install and configure zsh
|
||||
install_and_configure_shell() {
|
||||
if ! command_exists zsh && [ "$(uname)" == "Darwin" ]; then
|
||||
install_dependencies "$PACKAGE_MANAGER" zsh
|
||||
# Replaced by zinit in .zshrc
|
||||
# if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
||||
# git clone https://github.com/ohmyzsh/ohmyzsh.git "$HOME/.oh-my-zsh"
|
||||
# fi
|
||||
if [ "$SHELL" != "$(command -v zsh)" ]; then
|
||||
chsh -s "$(command -v zsh)"
|
||||
fi
|
||||
|
||||
exec zsh -l
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install essential tools
|
||||
install_essential_tools() {
|
||||
if ! command_exists curl; then
|
||||
install_dependencies "$PACKAGE_MANAGER" curl
|
||||
fi
|
||||
if ! command_exists unzip; then
|
||||
install_dependencies "$PACKAGE_MANAGER" unzip
|
||||
fi
|
||||
if ! command_exists git; then
|
||||
install_dependencies "$PACKAGE_MANAGER" git fd ripgrep fzf tree
|
||||
fi
|
||||
if ! command_exists nvim; then
|
||||
install_dependencies "$PACKAGE_MANAGER" neovim
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install Go
|
||||
install_go() {
|
||||
case $PACKAGE_MANAGER in
|
||||
"brew") install_dependencies "$PACKAGE_MANAGER" go ;;
|
||||
"apt-get" | "yum") install_dependencies "$PACKAGE_MANAGER" golang ;;
|
||||
*)
|
||||
echo "Unsupported package manager: $PACKAGE_MANAGER"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to install Python and Poetry
|
||||
install_python() {
|
||||
# Check if "global" argument is passed
|
||||
GLOBAL_INSTALL=true
|
||||
if [[ "$1" == "local" ]]; then
|
||||
GLOBAL_INSTALL=false
|
||||
fi
|
||||
|
||||
# Install pyenv if it's not already installed
|
||||
if ! command -v pyenv >/dev/null 2>&1; then
|
||||
echo "Installing pyenv..."
|
||||
curl https://pyenv.run | bash
|
||||
|
||||
# Set up pyenv in the current shell session
|
||||
export PATH="$HOME/.pyenv/bin:$PATH"
|
||||
eval "$(pyenv init --path)"
|
||||
eval "$(pyenv init -)"
|
||||
eval "$(pyenv virtualenv-init -)"
|
||||
fi
|
||||
|
||||
# Ensure Python 3.7+ is installed via pyenv
|
||||
REQUIRED_VERSION="3.7.0"
|
||||
# Function to check if the installed Python version is at least the required version
|
||||
check_python_version() {
|
||||
INSTALLED_VERSION=$(python -c "import sys; print('{}.{}'.format(sys.version_info.major, sys.version_info.minor))")
|
||||
|
||||
if [[ $(printf '%s\n' "$REQUIRED_VERSION" "$INSTALLED_VERSION" | sort -V | head -n 1) == "$REQUIRED_VERSION" ]]; then
|
||||
echo "Python version $INSTALLED_VERSION is installed and meets the requirement."
|
||||
else
|
||||
echo "Python version is less than $REQUIRED_VERSION. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_python_version
|
||||
|
||||
# Set Python version globally or locally
|
||||
if [[ "$GLOBAL_INSTALL" == true ]]; then
|
||||
echo "Setting Python $REQUIRED_VERSION as the global version..."
|
||||
pyenv global "$REQUIRED_VERSION"
|
||||
else
|
||||
echo "Setting Python $REQUIRED_VERSION as the local version..."
|
||||
pyenv local "$REQUIRED_VERSION"
|
||||
fi
|
||||
|
||||
# Rehash pyenv to make the new version available
|
||||
pyenv rehash
|
||||
|
||||
# Install Poetry using the pyenv-installed Python
|
||||
echo "Installing Poetry..."
|
||||
curl -sSL https://install.python-poetry.org | python3 -
|
||||
}
|
||||
|
||||
# Function to install all programming languages
|
||||
install_programming_languages() {
|
||||
install_go
|
||||
install_python global # Pass "global" as an argument to set Python globally
|
||||
}
|
||||
|
||||
# Function to install MesloLGS Nerd Font
|
||||
install_meslolgs_nerd_font() {
|
||||
if [ ! -f "$HOME/.local/share/fonts/MesloLGS NF Regular.ttf" ]; then
|
||||
mkdir -p ~/.local/share/fonts
|
||||
cd ~/.local/share/fonts || return
|
||||
curl -fLo "MesloLGS NF Regular.ttf" https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip
|
||||
unzip Meslo.zip -d meslo
|
||||
mv meslo/*.ttf ~/.local/share/fonts/
|
||||
rm -rf Meslo.zip meslo
|
||||
fc-cache -f -v
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to display installed dependencies
|
||||
show_installed_dependencies() {
|
||||
echo "Installed dependencies:"
|
||||
for dependency in "${INSTALLED_DEPENDENCIES[@]}"; do
|
||||
echo " - $dependency"
|
||||
done
|
||||
}
|
||||
|
||||
# Ensure HomeBrew is installed
|
||||
ensure_homebrew() {
|
||||
if ! command_exists brew; then
|
||||
echo "Installing Homebrew..."
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
echo "Updating Homebrew..."
|
||||
brew update
|
||||
}
|
||||
|
||||
# Function to start shell
|
||||
start_shell() {
|
||||
if command -v zsh &>/dev/null; then
|
||||
zsh
|
||||
elif command -v bash &>/dev/null; then
|
||||
bash
|
||||
elif command -v fish &>/dev/null; then
|
||||
fish
|
||||
else
|
||||
echo "Neither zsh nor bash is installed. Please install one of them manually."
|
||||
fi
|
||||
}
|
||||
|
||||
# Default values for flags
|
||||
ENABLE_AUTO_UPDATE=true
|
||||
DEPENDENCIES_FILE=""
|
||||
ADDITIONAL_DEPENDENCIES=()
|
||||
INSTALLED_DEPENDENCIES=()
|
||||
|
||||
# Parse command-line arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-a | --disable-auto-update)
|
||||
ENABLE_AUTO_UPDATE=false
|
||||
shift
|
||||
;;
|
||||
-d | --dependencies)
|
||||
DEPENDENCIES_FILE="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
ADDITIONAL_DEPENDENCIES+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Main script execution
|
||||
set_package_manager
|
||||
handle_auto_update
|
||||
install_essential_tools
|
||||
install_and_configure_shell
|
||||
install_programming_languages
|
||||
|
||||
# Install MesloLGS Nerd Font
|
||||
install_meslolgs_nerd_font
|
||||
|
||||
# Install dependencies from provided file if specified
|
||||
if [ -n "$DEPENDENCIES_FILE" ]; then
|
||||
install_dependency_list "$PACKAGE_MANAGER" "$DEPENDENCIES_FILE"
|
||||
fi
|
||||
|
||||
# Install additional dependencies provided as arguments
|
||||
if [ "${#ADDITIONAL_DEPENDENCIES[@]}" -gt 0 ]; then
|
||||
install_dependencies "$PACKAGE_MANAGER" "${ADDITIONAL_DEPENDENCIES[@]}"
|
||||
fi
|
||||
|
||||
show_installed_dependencies
|
||||
start_shell
|
||||
32
scripts/setup_macos_dock.sh
Executable file
32
scripts/setup_macos_dock.sh
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ "$(uname)" != "Darwin" ]; then
|
||||
echo "This script is only for MacOS"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Setup MacOS Dock
|
||||
defaults write com.apple.dock autohide -bool true
|
||||
defaults write com.apple.dock tilesize -int 50
|
||||
defaults write com.apple.dock largesize -int 64
|
||||
defaults write com.apple.dock magnification -bool false
|
||||
defaults write com.apple.dock orientation -string "bottom"
|
||||
defaults write com.apple.dock mineffect -string ""
|
||||
defaults write -g NSAutomaticWindowAnimationsEnabled -bool false
|
||||
|
||||
if ! command -v dockutil &>/dev/null; then
|
||||
echo "dockutil is not installed. Installing..."
|
||||
brew install dockutil
|
||||
fi
|
||||
|
||||
dockutil --remove all
|
||||
|
||||
dockutil --add "/System/Applications/Mail.app/"
|
||||
dockutil --add "/System/Applications/Messages.app/"
|
||||
dockutil --add "/Applications/WezTerm.app"
|
||||
dockutil --add "/Applications/Obsidian.app"
|
||||
dockutil --add "/Applications/Zen.app"
|
||||
dockutil --add "/System/Applications/System Settings.app"
|
||||
|
||||
# Restart the Dock to apply changes
|
||||
killall Dock
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
BREW_PREFIX="/usr/local/bin/"
|
||||
BREW_LIST_DIR="$HOME/.local/bin/.brew_lists"
|
||||
BREW_LIST="$BREW_LIST_DIR/brew_list.txt"
|
||||
CASK_LIST="$BREW_LIST_DIR/cask_list.txt"
|
||||
NEW_BREW_LIST="$BREW_LIST_DIR/brew_list.txt.new"
|
||||
NEW_CASK_LIST="$BREW_LIST_DIR/cask_list.txt.new"
|
||||
|
||||
# Function to check if the lists are different
|
||||
are_lists_different() {
|
||||
diff -q "$1" "$2" &>/dev/null
|
||||
}
|
||||
|
||||
# Function to update the brew and cask lists
|
||||
update_lists() {
|
||||
echo "Updating brew list..."
|
||||
"$BREW_PREFIX"brew list --formula >"$NEW_BREW_LIST"
|
||||
chmod 664 "$NEW_BREW_LIST"
|
||||
|
||||
echo "Updating cask list..."
|
||||
"$BREW_PREFIX"brew list --cask >"$NEW_CASK_LIST"
|
||||
chmod 664 "$NEW_CASK_LIST"
|
||||
}
|
||||
|
||||
# Function to install Homebrew and packages
|
||||
install_packages() {
|
||||
# Install Homebrew if not installed
|
||||
if ! command -v "$BREW_PREFIX"brew &>/dev/null; then
|
||||
echo "Installing Homebrew..."
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
|
||||
# Install brew packages
|
||||
if [ -s "$BREW_LIST" ]; then
|
||||
echo "Installing brew packages..."
|
||||
xargs "$BREW_PREFIX"brew install <"$BREW_LIST"
|
||||
echo "Brew packages installed successfully."
|
||||
fi
|
||||
|
||||
# Install cask packages
|
||||
if [ -s "$CASK_LIST" ]; then
|
||||
echo "Installing cask packages..."
|
||||
xargs "$BREW_PREFIX"brew install --cask <"$CASK_LIST"
|
||||
echo "Cask packages installed successfully."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to save lists to specified directories
|
||||
save_lists() {
|
||||
echo "Saving updated lists to specified directories..."
|
||||
|
||||
mv "$NEW_BREW_LIST" "$BREW_LIST"
|
||||
mv "$NEW_CASK_LIST" "$CASK_LIST"
|
||||
|
||||
echo "Lists saved successfully."
|
||||
}
|
||||
|
||||
# Function to commit changes to Git
|
||||
commit_to_git() {
|
||||
current_dir=$PWD
|
||||
cd "$HOME"/.local/bin || exit
|
||||
git pull
|
||||
git add "$BREW_LIST" "$CASK_LIST"
|
||||
git commit -m "Update brew lists"
|
||||
git push origin main
|
||||
cd "$current_dir" || exit
|
||||
}
|
||||
|
||||
# Check command-line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--install)
|
||||
install_packages
|
||||
exit 0
|
||||
;;
|
||||
--save-brew-dir)
|
||||
shift
|
||||
"$BREW_PREFIX"brew autoupdate start
|
||||
;;
|
||||
--save-cask-dir)
|
||||
shift
|
||||
CASK_LIST_DIR="$1"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid argument: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Check if the lists directories exist, if not, create them
|
||||
if [ ! -d "$BREW_LIST_DIR" ]; then
|
||||
mkdir "$BREW_LIST_DIR"
|
||||
fi
|
||||
|
||||
if [ ! -d "$CASK_LIST_DIR" ]; then
|
||||
mkdir "$CASK_LIST_DIR"
|
||||
fi
|
||||
|
||||
# Update the lists
|
||||
update_lists
|
||||
|
||||
# Check if the lists have changed
|
||||
if are_lists_different "$NEW_BREW_LIST" "$BREW_LIST" || are_lists_different "$NEW_CASK_LIST" "$CASK_LIST"; then
|
||||
# Lists have changed, save the updated lists
|
||||
save_lists
|
||||
|
||||
# Commit changes to Git
|
||||
commit_to_git
|
||||
fi
|
||||
|
||||
112
scripts/update_brew_lists.sh
Executable file
112
scripts/update_brew_lists.sh
Executable file
|
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
BREW_CMD="$HOMEBREW_PREFIX"/bin/brew
|
||||
BREW_LIST_DIR="$HOME/.local/bin/.brew_lists"
|
||||
BREW_LIST="$BREW_LIST_DIR/brew_list.txt"
|
||||
CASK_LIST="$BREW_LIST_DIR/cask_list.txt"
|
||||
NEW_BREW_LIST="$BREW_LIST_DIR/brew_list.txt.new"
|
||||
NEW_CASK_LIST="$BREW_LIST_DIR/cask_list.txt.new"
|
||||
|
||||
# Function to check if the lists are different
|
||||
are_lists_different() {
|
||||
diff -q "$1" "$2" &>/dev/null
|
||||
}
|
||||
|
||||
# Function to update the brew and cask lists
|
||||
update_lists() {
|
||||
echo "Updating brew list..."
|
||||
"$BREW_CMD" list --formula >"$NEW_BREW_LIST"
|
||||
chmod 664 "$NEW_BREW_LIST"
|
||||
|
||||
echo "Updating cask list..."
|
||||
"$BREW_CMD" list --cask >"$NEW_CASK_LIST"
|
||||
chmod 664 "$NEW_CASK_LIST"
|
||||
}
|
||||
|
||||
# Function to install Homebrew and packages
|
||||
install_packages() {
|
||||
# Install Homebrew if not installed
|
||||
if ! command -v "$BREW_PREFIX"brew &>/dev/null; then
|
||||
echo "Installing Homebrew..."
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
|
||||
# Install brew packages
|
||||
if [ -s "$BREW_LIST" ]; then
|
||||
echo "Installing brew packages..."
|
||||
xargs "$BREW_CMD" install <"$BREW_LIST"
|
||||
echo "Brew packages installed successfully."
|
||||
fi
|
||||
|
||||
# Install cask packages
|
||||
if [ -s "$CASK_LIST" ]; then
|
||||
echo "Installing cask packages..."
|
||||
xargs "$BREW_CMD" install --cask <"$CASK_LIST"
|
||||
echo "Cask packages installed successfully."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to save lists to specified directories
|
||||
save_lists() {
|
||||
echo "Saving updated lists to specified directories..."
|
||||
|
||||
mv "$NEW_BREW_LIST" "$BREW_LIST"
|
||||
mv "$NEW_CASK_LIST" "$CASK_LIST"
|
||||
|
||||
echo "Lists saved successfully."
|
||||
}
|
||||
|
||||
# Function to commit changes to Git
|
||||
commit_to_git() {
|
||||
current_dir=$PWD
|
||||
cd "$HOME"/.local/bin || exit
|
||||
git pull
|
||||
git add "$BREW_LIST" "$CASK_LIST"
|
||||
git commit -m "Update brew lists"
|
||||
git push origin main
|
||||
cd "$current_dir" || exit
|
||||
}
|
||||
|
||||
# Check command-line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--install)
|
||||
install_packages
|
||||
exit 0
|
||||
;;
|
||||
--save-brew-dir)
|
||||
shift
|
||||
"$BREW_CMD" autoupdate start
|
||||
;;
|
||||
--save-cask-dir)
|
||||
shift
|
||||
CASK_LIST_DIR="$1"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid argument: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Check if the lists directories exist, if not, create them
|
||||
if [ ! -d "$BREW_LIST_DIR" ]; then
|
||||
mkdir -p "$BREW_LIST_DIR"
|
||||
fi
|
||||
|
||||
if [ ! -d "$CASK_LIST_DIR" ]; then
|
||||
mkdir -p "$CASK_LIST_DIR"
|
||||
fi
|
||||
|
||||
# Update the lists
|
||||
update_lists
|
||||
|
||||
# Check if the lists have changed
|
||||
if are_lists_different "$NEW_BREW_LIST" "$BREW_LIST" || are_lists_different "$NEW_CASK_LIST" "$CASK_LIST"; then
|
||||
# Lists have changed, save the updated lists
|
||||
save_lists
|
||||
|
||||
# Commit changes to Git
|
||||
commit_to_git
|
||||
fi
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
MAX_VOLUME=50
|
||||
ONLY_ON_HEADPHONES=false
|
||||
NOTIFICATION_TITLE="Volume Limiter"
|
||||
HEADPHONES_CONNECTED=false
|
||||
DELAY=3
|
||||
|
||||
# Function to get the current volume on macOS
|
||||
get_current_volume_macos() {
|
||||
osascript -e "output volume of (get volume settings)"
|
||||
}
|
||||
|
||||
# Function to set the volume on macOS
|
||||
set_volume_macos() {
|
||||
osascript -e "set volume output volume $1"
|
||||
}
|
||||
|
||||
# Function to display notification on macOS if not already displayed
|
||||
display_notification_macos() {
|
||||
local title="$1"
|
||||
local subtitle="$2"
|
||||
local notification_file="/tmp/volume_notification"
|
||||
|
||||
if [[ -f "$notification_file" ]]; then
|
||||
local last_notification
|
||||
last_notification=$(cat "$notification_file")
|
||||
if [[ "$last_notification" == "$subtitle" ]]; then
|
||||
return 0 # Notification already displayed
|
||||
fi
|
||||
fi
|
||||
|
||||
osascript -e "display notification \"$subtitle\" with title \"$title\""
|
||||
echo "$subtitle" >"$notification_file"
|
||||
}
|
||||
|
||||
# Function to check if output is on internal speakers on macOS
|
||||
on_speaker_macos() {
|
||||
local output_source
|
||||
output_source=$(/usr/sbin/system_profiler SPAudioDataType | awk '/Output Source/ {print $NF}')
|
||||
|
||||
# Check if 'Default' is found in the output source
|
||||
if echo "$output_source" | grep -q 'Default'; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to get the current volume on Linux
|
||||
get_current_volume_linux() {
|
||||
amixer get Master | grep -oP '\d+%' | head -1 | tr -d '%'
|
||||
}
|
||||
|
||||
# Function to set the volume on Linux
|
||||
set_volume_linux() {
|
||||
amixer set Master "$1%"
|
||||
}
|
||||
|
||||
# Function to display notification on Linux if not already displayed
|
||||
display_notification_linux() {
|
||||
local title="$1"
|
||||
local subtitle="$2"
|
||||
local notification_file="/tmp/volume_notification"
|
||||
|
||||
if [[ -f "$notification_file" ]]; then
|
||||
local last_notification
|
||||
last_notification=$(cat "$notification_file")
|
||||
if [[ "$last_notification" == "$subtitle" ]]; then
|
||||
return 0 # Notification already displayed
|
||||
fi
|
||||
fi
|
||||
|
||||
notify-send "$title" "$subtitle"
|
||||
echo "$subtitle" >"$notification_file"
|
||||
}
|
||||
|
||||
# Function to check if output is on internal speakers on Linux
|
||||
on_speaker_linux() {
|
||||
pacmd list-sinks | grep -q 'active port.*analog-output-speaker'
|
||||
}
|
||||
|
||||
# Function to check if headphones are connected
|
||||
check_headphones() {
|
||||
if [ "$ONLY_ON_HEADPHONES" = true ]; then
|
||||
if $on_speaker; then
|
||||
if [ "$HEADPHONES_CONNECTED" = true ]; then
|
||||
HEADPHONES_CONNECTED=false
|
||||
$display_notification "$NOTIFICATION_TITLE" "Volume limiter is stopped, be careful"
|
||||
fi
|
||||
else
|
||||
if [ "$HEADPHONES_CONNECTED" = false ]; then
|
||||
HEADPHONES_CONNECTED=true
|
||||
limit_volume
|
||||
$display_notification "$NOTIFICATION_TITLE" "Limiting your 🎧 headphones to $MAX_VOLUME% to protect your ears"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to limit volume
|
||||
limit_volume() {
|
||||
local current_volume
|
||||
current_volume=$($get_current_volume)
|
||||
if [ "$ONLY_ON_HEADPHONES" = true ]; then
|
||||
if [ "$HEADPHONES_CONNECTED" = true ] && [ "$current_volume" -gt "$MAX_VOLUME" ]; then
|
||||
$set_volume "$MAX_VOLUME"
|
||||
fi
|
||||
else
|
||||
if [ "$current_volume" -gt "$MAX_VOLUME" ]; then
|
||||
$set_volume "$MAX_VOLUME"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Main logic
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
get_current_volume="get_current_volume_macos"
|
||||
set_volume="set_volume_macos"
|
||||
display_notification="display_notification_macos"
|
||||
on_speaker="on_speaker_macos"
|
||||
else
|
||||
# Linux
|
||||
get_current_volume="get_current_volume_linux"
|
||||
set_volume="set_volume_linux"
|
||||
display_notification="display_notification_linux"
|
||||
on_speaker="on_speaker_linux"
|
||||
fi
|
||||
|
||||
# Parse command-line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--headphones-only)
|
||||
ONLY_ON_HEADPHONES=true
|
||||
shift
|
||||
;;
|
||||
--max-volume)
|
||||
if [[ "$2" =~ ^[0-9]+$ && "$2" -ge 0 && "$2" -le 100 ]]; then
|
||||
MAX_VOLUME="$2"
|
||||
shift 2
|
||||
else
|
||||
echo "Error: --max-volume must be followed by a valid percentage (0-100)."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--delay)
|
||||
if [[ "$2" =~ ^[0-9]+$ && "$2" -gt 0 ]]; then
|
||||
DELAY="$2"
|
||||
shift 2
|
||||
else
|
||||
echo "Error: --delay must be followed by a valid positive integer."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [--headphones-only] [--max-volume <percentage>] [--delay <seconds>] [--macos | --linux]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for ((i = 1; i <= $((60 / DELAY)); i++)); do
|
||||
check_headphones
|
||||
limit_volume
|
||||
|
||||
sleep "$DELAY"
|
||||
done
|
||||
|
||||
168
scripts/volumizer.sh
Executable file
168
scripts/volumizer.sh
Executable file
|
|
@ -0,0 +1,168 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
MAX_VOLUME=50
|
||||
ONLY_ON_HEADPHONES=false
|
||||
NOTIFICATION_TITLE="Volume Limiter"
|
||||
HEADPHONES_CONNECTED=false
|
||||
DELAY=3
|
||||
|
||||
# Function to get the current volume on macOS
|
||||
get_current_volume_macos() {
|
||||
osascript -e "output volume of (get volume settings)"
|
||||
}
|
||||
|
||||
# Function to set the volume on macOS
|
||||
set_volume_macos() {
|
||||
osascript -e "set volume output volume $1"
|
||||
}
|
||||
|
||||
# Function to display notification on macOS if not already displayed
|
||||
display_notification_macos() {
|
||||
local title="$1"
|
||||
local subtitle="$2"
|
||||
local notification_file="/tmp/volume_notification"
|
||||
|
||||
if [[ -f "$notification_file" ]]; then
|
||||
local last_notification
|
||||
last_notification=$(cat "$notification_file")
|
||||
if [[ "$last_notification" == "$subtitle" ]]; then
|
||||
return 0 # Notification already displayed
|
||||
fi
|
||||
fi
|
||||
|
||||
osascript -e "display notification \"$subtitle\" with title \"$title\""
|
||||
echo "$subtitle" >"$notification_file"
|
||||
}
|
||||
|
||||
# Function to display notification on Linux if not already displayed
|
||||
display_notification_linux() {
|
||||
local title="$1"
|
||||
local subtitle="$2"
|
||||
local notification_file="/tmp/volume_notification"
|
||||
|
||||
if [[ -f "$notification_file" ]]; then
|
||||
local last_notification
|
||||
last_notification=$(cat "$notification_file")
|
||||
if [[ "$last_notification" == "$subtitle" ]]; then
|
||||
return 0 # Notification already displayed
|
||||
fi
|
||||
fi
|
||||
|
||||
notify-send "$title" "$subtitle"
|
||||
echo "$subtitle" >"$notification_file"
|
||||
}
|
||||
|
||||
# Function to check if output is on internal speakers on macOS
|
||||
on_speaker_macos() {
|
||||
local output_source
|
||||
output_source=$(/usr/sbin/system_profiler SPAudioDataType | awk '/Output Source/ {print $NF}')
|
||||
|
||||
# Check if 'Default' is found in the output source
|
||||
if echo "$output_source" | grep -q 'Default'; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check if output is on internal speakers on Linux
|
||||
on_speaker_linux() {
|
||||
pacmd list-sinks | grep -q 'active port.*analog-output-speaker'
|
||||
}
|
||||
|
||||
# Function to get the current volume on Linux
|
||||
get_current_volume_linux() {
|
||||
amixer get Master | grep -oP '\d+%' | head -1 | tr -d '%'
|
||||
}
|
||||
|
||||
# Function to set the volume on Linux
|
||||
set_volume_linux() {
|
||||
amixer set Master "$1%"
|
||||
}
|
||||
|
||||
# Function to check if headphones are connected
|
||||
check_headphones() {
|
||||
if [ "$ONLY_ON_HEADPHONES" = true ]; then
|
||||
if $on_speaker; then
|
||||
if [ "$HEADPHONES_CONNECTED" = true ]; then
|
||||
HEADPHONES_CONNECTED=false
|
||||
$display_notification "$NOTIFICATION_TITLE" "Volume limiter is stopped, be careful"
|
||||
fi
|
||||
else
|
||||
if [ "$HEADPHONES_CONNECTED" = false ]; then
|
||||
HEADPHONES_CONNECTED=true
|
||||
limit_volume
|
||||
$display_notification "$NOTIFICATION_TITLE" "Limiting your 🎧 headphones to $MAX_VOLUME% to protect your ears"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to limit volume
|
||||
limit_volume() {
|
||||
local current_volume
|
||||
current_volume=$($get_current_volume)
|
||||
if [ "$ONLY_ON_HEADPHONES" = true ]; then
|
||||
if [ "$HEADPHONES_CONNECTED" = true ] && [ "$current_volume" -gt "$MAX_VOLUME" ]; then
|
||||
$set_volume "$MAX_VOLUME"
|
||||
fi
|
||||
else
|
||||
if [ "$current_volume" -gt "$MAX_VOLUME" ]; then
|
||||
$set_volume "$MAX_VOLUME"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Main logic
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
get_current_volume="get_current_volume_macos"
|
||||
set_volume="set_volume_macos"
|
||||
display_notification="display_notification_macos"
|
||||
on_speaker="on_speaker_macos"
|
||||
else
|
||||
# Linux
|
||||
get_current_volume="get_current_volume_linux"
|
||||
set_volume="set_volume_linux"
|
||||
display_notification="display_notification_linux"
|
||||
on_speaker="on_speaker_linux"
|
||||
fi
|
||||
|
||||
# Parse command-line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--headphones-only)
|
||||
ONLY_ON_HEADPHONES=true
|
||||
shift
|
||||
;;
|
||||
--max-volume)
|
||||
if [[ "$2" =~ ^[0-9]+$ && "$2" -ge 0 && "$2" -le 100 ]]; then
|
||||
MAX_VOLUME="$2"
|
||||
shift 2
|
||||
else
|
||||
echo "Error: --max-volume must be followed by a valid percentage (0-100)."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--delay)
|
||||
if [[ "$2" =~ ^[0-9]+$ && "$2" -gt 0 ]]; then
|
||||
DELAY="$2"
|
||||
shift 2
|
||||
else
|
||||
echo "Error: --delay must be followed by a valid positive integer."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [--headphones-only] [--max-volume <percentage>] [--delay <seconds>] [--macos | --linux]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for ((i = 1; i <= $((60 / DELAY)); i++)); do
|
||||
check_headphones
|
||||
limit_volume
|
||||
|
||||
sleep "$DELAY"
|
||||
done
|
||||
25
scripts/wzp
25
scripts/wzp
|
|
@ -1,25 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# WezTerm Project - Start a new WezTerm profile
|
||||
PROFILES_DIR="$HOME/.config/wezterm/profiles/"
|
||||
FZF_THEME=$("$HOME"/.local/bin/scripts/fzf_theme)
|
||||
profile=""
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
# List all Lua files in the projects directory and prompt for selection
|
||||
profile=$(fd -d 1 -e lua -t f . "$PROFILES_DIR" --print0 | xargs -0 -n 1 basename | sed 's/\.lua$//' | fzf "$FZF_THEME" --cycle --no-info --layout=reverse)
|
||||
else
|
||||
if [[ ! -e "$PROFILES_DIR/$1.lua" ]]; then
|
||||
echo "The profile file '$PROFILES_DIR/$1.lua' does not exist"
|
||||
exit 1
|
||||
fi
|
||||
profile="$1"
|
||||
fi
|
||||
|
||||
if [[ -z $profile ]]; then
|
||||
echo "No profile selected"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start WezTerm with the selected project profile
|
||||
WZ_PROFILE="$profile" wezterm start --always-new-process >/dev/null 2>&1 &
|
||||
25
scripts/wzp.sh
Executable file
25
scripts/wzp.sh
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# WezTerm Project - Start a new WezTerm profile
|
||||
PROFILES_DIR="$HOME/.config/wezterm/profiles/"
|
||||
FZF_THEME=$("$HOME"/.local/bin/scripts/fzf_theme.sh)
|
||||
profile="default"
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
# List all Lua files in the projects directory and prompt for selection
|
||||
profile=$(fd -d 1 -e lua -t f . "$PROFILES_DIR" --print0 | xargs -0 -n 1 basename | sed 's/\.lua$//' | fzf "$FZF_THEME" --cycle --no-info --layout=reverse)
|
||||
else
|
||||
if [[ ! -e "$PROFILES_DIR/$1.lua" ]]; then
|
||||
echo "The profile file '$PROFILES_DIR/$1.lua' does not exist"
|
||||
exit 1
|
||||
fi
|
||||
profile="$1"
|
||||
fi
|
||||
|
||||
if [[ -z $profile ]]; then
|
||||
echo "No profile selected"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start WezTerm with the selected project profile
|
||||
WZ_PROFILE="$profile" wezterm start --always-new-process >/dev/null 2>&1 &
|
||||
Loading…
Reference in a new issue