diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 0000000..aca0b98 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,16 @@ +[credential "https://github.com"] + helper = + helper = !/usr/bin/gh auth git-credential +[credential "https://gist.github.com"] + helper = + helper = !/usr/bin/gh auth git-credential +[user] + email = peter@peterwood.dev + name = Peter Wood +[pull] + rebase = false +[init] + defaultBranch = main +[core] + autocrlf = input + eol = lf diff --git a/README.md b/README.md index 8b07966..72971bd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Shell Scripts Documentation +# Shell Scripts and Dotfiles Repository -This repository contains various shell scripts for managing media-related tasks. +This repository contains various shell scripts for managing media-related tasks and dotfiles for system configuration. ## Available Scripts @@ -15,6 +15,16 @@ This repository contains various shell scripts for managing media-related tasks. - [Plex Management Script Documentation](./docs/plex-management.md): Detailed documentation for the `plex.sh` script. - [Folder Metrics Script Documentation](./docs/folder-metrics.md): Detailed documentation for the `folder-metrics.sh` script. +## Dotfiles + +The repository includes dotfiles for system configuration in the `dotfiles` directory. These can be automatically set up using the bootstrap script: + +```bash +curl -fsSL https://raw.githubusercontent.com/acedanger/shell/main/bootstrap.sh | bash +``` + +For more information about the dotfiles, see [Dotfiles README](./dotfiles/README.md). + # plex.sh This script is used to manage the Plex Media Server service on a systemd-based Linux distribution. It provides the following functionalities: diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..778e5b3 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +DOTFILES_REPO="acedanger/shell" +DOTFILES_BRANCH="main" +DOTFILES_DIR="$HOME/shell" + +# Colors for output +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +echo -e "${GREEN}Setting up your system...${NC}" + +# Install git if not present +if ! command -v git &>/dev/null; then + echo -e "${YELLOW}Installing git...${NC}" + sudo apt update && sudo apt install -y git +fi + +# Create shell directory if it doesn't exist +mkdir -p "$HOME/shell" + +# Clone or update repository +if [ -d "$DOTFILES_DIR" ]; then + echo -e "${YELLOW}Updating existing shell repository...${NC}" + cd "$DOTFILES_DIR" + git pull origin $DOTFILES_BRANCH +else + echo -e "${YELLOW}Cloning shell repository...${NC}" + git clone "https://github.com/$DOTFILES_REPO.git" "$DOTFILES_DIR" + cd "$DOTFILES_DIR" +fi + +# Make scripts executable +chmod +x "$DOTFILES_DIR/setup/setup.sh" + +# Run setup script +"$DOTFILES_DIR/setup/setup.sh" + +echo -e "${GREEN}Bootstrap completed! Please restart your terminal for changes to take effect.${NC}" diff --git a/dotfiles/.gitconfig b/dotfiles/.gitconfig new file mode 100644 index 0000000..aca0b98 --- /dev/null +++ b/dotfiles/.gitconfig @@ -0,0 +1,16 @@ +[credential "https://github.com"] + helper = + helper = !/usr/bin/gh auth git-credential +[credential "https://gist.github.com"] + helper = + helper = !/usr/bin/gh auth git-credential +[user] + email = peter@peterwood.dev + name = Peter Wood +[pull] + rebase = false +[init] + defaultBranch = main +[core] + autocrlf = input + eol = lf diff --git a/dotfiles/.nanorc b/dotfiles/.nanorc new file mode 100644 index 0000000..48945cd --- /dev/null +++ b/dotfiles/.nanorc @@ -0,0 +1,3 @@ +set linenumbers +set softwrap +set atblanks diff --git a/dotfiles/.profile b/dotfiles/.profile new file mode 100644 index 0000000..51df3d7 --- /dev/null +++ b/dotfiles/.profile @@ -0,0 +1,29 @@ +# ~/.profile: executed by the command interpreter for login shells. +# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login +# exists. +# see /usr/share/doc/bash/examples/startup-files for examples. +# the files are located in the bash-doc package. + +# the default umask is set in /etc/profile; for setting the umask +# for ssh logins, install and configure the libpam-umask package. +#umask 022 + +# if running bash +if [ -n "$BASH_VERSION" ]; then + # include .bashrc if it exists + if [ -f "$HOME/.bashrc" ]; then + . "$HOME/.bashrc" + fi +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/.local/bin" ] ; then + PATH="$HOME/.local/bin:$PATH" +fi + +nvm use stable diff --git a/dotfiles/.zshrc b/dotfiles/.zshrc new file mode 100644 index 0000000..78a3d51 --- /dev/null +++ b/dotfiles/.zshrc @@ -0,0 +1,113 @@ +# If you come from bash you might have to change your $PATH. +# export PATH=$HOME/bin:/usr/local/bin:$PATH +export PATH=$PATH:$HOME/.local/bin + +# Path to your oh-my-zsh installation. +export ZSH="/home/acedanger/.oh-my-zsh" + +# Set name of the theme to load --- if set to "random", it will +# load a random theme each time oh-my-zsh is loaded, in which case, +# to know which specific one was loaded, run: echo $RANDOM_THEME +# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes +ZSH_THEME="agnoster" + +# Uncomment the following line to use hyphen-insensitive completion. +# Case-sensitive completion must be off. _ and - will be interchangeable. +HYPHEN_INSENSITIVE="true" + +# Uncomment the following line to disable bi-weekly auto-update checks. +# DISABLE_AUTO_UPDATE="true" + +# Uncomment the following line to automatically update without prompting. +# DISABLE_UPDATE_PROMPT="true" + +# Uncomment the following line if pasting URLs and other text is messed up. +# DISABLE_MAGIC_FUNCTIONS="true" + +# Uncomment the following line to disable colors in ls. +# DISABLE_LS_COLORS="true" + +# Uncomment the following line to disable auto-setting terminal title. +# DISABLE_AUTO_TITLE="true" + +# Uncomment the following line to enable command auto-correction. +# ENABLE_CORRECTION="true" + +# Uncomment the following line to display red dots whilst waiting for completion. +# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work) +# See https://github.com/ohmyzsh/ohmyzsh/issues/5765 +# COMPLETION_WAITING_DOTS="true" + +# Uncomment the following line if you want to disable marking untracked files +# under VCS as dirty. This makes repository status check for large repositories +# much, much faster. +# DISABLE_UNTRACKED_FILES_DIRTY="true" + +# Standard plugins can be found in $ZSH/plugins/ +# Custom plugins may be added to $ZSH_CUSTOM/plugins/ +# Add wisely, as too many plugins slow down shell startup. +plugins=(git zsh-autosuggestions zsh-syntax-highlighting docker docker-compose zsh-you-should-use z ssh) + +export ZSH_COMPDUMP=$ZSH/cache/.zcompdump-$HOST +source $ZSH/oh-my-zsh.sh + +# Initialize zoxide +eval "$(zoxide init zsh)" + +# User configuration +# export MANPATH="/usr/local/man:$MANPATH" + +# You may need to manually set your language environment +# export LANG=en_US.UTF-8 + +# Preferred editor for local and remote sessions +# if [[ -n $SSH_CONNECTION ]]; then +# export EDITOR='vim' +# else +# export EDITOR='mvim' +# fi + +# Compilation flags +# export ARCHFLAGS="-arch x86_64" + +# Set personal aliases, overriding those provided by oh-my-zsh libs, +# plugins, and themes. Aliases can be placed here, though oh-my-zsh +# users are encouraged to define aliases within the ZSH_CUSTOM folder. +# For a full list of active aliases, run `alias`. + +# Load custom aliases +if [ -f "$ZSH_CUSTOM/aliases.zsh" ]; then + source "$ZSH_CUSTOM/aliases.zsh" +fi + +# set directory to home +cd ~ + +if [ -x /usr/games/cowsay -a -x /usr/games/fortune -a -x /usr/games/lolcat ]; then + fortune -s | cowsay | lolcat +fi + +# NVM configuration +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + +# Automatically use node version specified in .nvmrc if present +autoload -U add-zsh-hook +load-nvmrc() { + local nvmrc_path="$(nvm_find_nvmrc)" + if [ -n "$nvmrc_path" ]; then + local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") + if [ "$nvmrc_node_version" = "N/A" ]; then + nvm install + elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then + nvm use + fi + elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then + nvm use default + fi +} +add-zsh-hook chpwd load-nvmrc +load-nvmrc + +[[ -s /home/acedanger/.autojump/etc/profile.d/autojump.sh ]] && source /home/acedanger/.autojump/etc/profile.d/autojump.sh autoload -U compinit && compinit -u diff --git a/dotfiles/Microsoft.PowerShell_profile.ps1 b/dotfiles/Microsoft.PowerShell_profile.ps1 new file mode 100644 index 0000000..a80787d --- /dev/null +++ b/dotfiles/Microsoft.PowerShell_profile.ps1 @@ -0,0 +1,188 @@ +# +$canConnectToGitHub = Test-Connection github.com -Count 1 -Quiet -TimeoutSeconds 1 + +function Install-CustomModules { + param ( + [string]$ModuleName = '' + ) + # check if module is installed + $moduleInfo = Get-Module -ListAvailable -Name $ModuleName -ErrorAction SilentlyContinue + if ($moduleInfo) { return } + + Write-Host "${ModuleName} module not found." -ForegroundColor Red + Install-Module -Name $ModuleName -Scope CurrentUser + + Import-Module -Name $ModuleName +} + +Install-CustomModules -ModuleName 'tiPS' +Install-CustomModules -ModuleName 'PSScriptAnalyzer' +Install-CustomModules -ModuleName 'Terminal-Icons' +Install-CustomModules -ModuleName 'PSReadLine' +Install-CustomModules -ModuleName 'PSWindowsUpdate' + +# kali.omp.json +oh-my-posh --init --shell pwsh --config "$env:OneDrive\Documents\PowerShell\prompt\themes\stelbent-compact.minimal.omp.json" | Invoke-Expression + +Set-PSReadLineOption -PredictionSource History +Set-PSReadLineOption -PredictionViewStyle ListView +Set-PSReadLineOption -EditMode Windows +Set-PSReadLineKeyHandler -Key Tab -Function Complete + +Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() + $Local:word = $wordToComplete.Replace('"', '""') + $Local:ast = $commandAst.ToString().Replace('"', '""') + winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } +} +function Get-Ip-Address { + (Invoke-WebRequest -Uri ifconfig.me/ip).Content +} + +Set-Alias getIp Get-Ip-Address + +function Invoke-WslReboot() { + param ( + [string]$Distro = 'Debian' + ) + Write-Host "Rebooting $Distro" + wsl --shutdown +} + +Set-Alias wslreboot Invoke-WslReboot + +function Update-Budget() { + Write-Host "Updating budget database" + py D:\dev\export-budget-csv\export.py -s "$env:OneDrive\Documents\Financial\Wood Family Financials.xlsx" + Write-Host "Budget database updated" +} + +Set-Alias updbudget Update-Budget + +function Update-Winget() { + winget upgrade +} + +Set-Alias wgu Update-Winget +#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module + +Import-Module -Name Microsoft.WinGet.CommandNotFound +#f45873b3-b655-43a6-b217-97c00aa0db58 + +if (Get-Command zoxide -ErrorAction SilentlyContinue) { + Invoke-Expression (& { (zoxide init powershell | Out-String) }) +} +else { + Write-Host "zoxide command not found. Attempting to install via winget..." + try { + winget install -e --id ajeetdsouza.zoxide + Write-Host "zoxide installed successfully. Initializing..." + Invoke-Expression (& { (zoxide init powershell | Out-String) }) + } + catch { + Write-Error "Failed to install zoxide. Error: $_" + } +} + +Set-TiPSConfiguration -AutomaticallyWritePowerShellTip EverySession + +# Finds files recursively matching a pattern. +function ff($name) { + Get-ChildItem -Recurse -Filter "*${name}*" -ErrorAction SilentlyContinue | ForEach-Object { Write-Output "${$_.directory}\$(%_)" } +} + +# Creates an empty file (similar to the touch command in Linux). +function touch($file) { + "" | Out-File -File $file -Encoding ascii +} + +# Reloads the current profile. +function Update-Profile { + & $PROFILE +} + +# Checks for and updates PowerShell to the latest version. +function Update-PowerShell { + if (-not $global:canConnectToGitHub) { + Write-Host "Skipping PowerShell update check due to GitHub.com not responding within 1 second." -ForegroundColor Yellow + return + } + + try { + Write-Host "Checking for PowerShell updates..." -ForegroundColor Cyan + $updateNeeded = $false + $currentVersion = $PSVersionTable.PSVersion.ToString() + $gitHubApiUrl = "https://api.github.com/repos/PowerShell/PowerShell/releases/latest" + $latestReleaseInfo = Invoke-RestMethod -Uri $gitHubApiUrl + $latestVersion = $latestReleaseInfo.tag_name.Trim('v') + if ($currentVersion -lt $latestVersion) { + $updateNeeded = $true + } + + if ($updateNeeded) { + Write-Host "Updating PowerShell..." -ForegroundColor Yellow + winget upgrade "Microsoft.PowerShell" --accept-source-agreements --accept-package-agreements + Write-Host "PowerShell has been updated. Please restart your shell to reflect changes" -ForegroundColor Magenta + } + else { + Write-Host "Your PowerShell is up to date." -ForegroundColor Green + } + } + catch { + Write-Error "Failed to update PowerShell. Error: $_" + } +} +Update-PowerShell + +# Searches for a regular expression in files (similar to the grep command in Linux). +function grep($regex, $dir) { + if ( $dir ) { + Get-ChildItem $dir | select-string $regex + return + } + $input | select-string $regex +} + +# Displays disk volume information. +function df { + get-volume +} + +# Displays the first n lines of a file8587 +function head { + param($Path, $n = 10) + Get-Content $Path -Head $n +} + +# Displays the last n lines of a file +function tail { + param($Path, $n = 10) + Get-Content $Path -Tail $n +} + +# Navigates to the Documents directory. +function docs { Set-Location -Path $HOME\Documents } + +# Navigates to the Downloads directory. +function dl { Set-Location -Path $HOME\Downloads } + +# Clears the DNS client cache. +function flushdns { Clear-DnsClientCache } + +# Copies text to the clipboard. +function cpy { Set-Clipboard $args[0] } + +# Gets the text from the clipboard. +function pst { Get-Clipboard } + +# Enhanced PowerShell Experience +Set-PSReadLineOption -Colors @{ + Command = 'Yellow' + Parameter = 'Green' + String = 'DarkCyan' +} + +# http://bin.christitus.com/unakijolon \ No newline at end of file diff --git a/dotfiles/Microsoft.VSCode_profile.ps1 b/dotfiles/Microsoft.VSCode_profile.ps1 new file mode 100644 index 0000000..a80787d --- /dev/null +++ b/dotfiles/Microsoft.VSCode_profile.ps1 @@ -0,0 +1,188 @@ +# +$canConnectToGitHub = Test-Connection github.com -Count 1 -Quiet -TimeoutSeconds 1 + +function Install-CustomModules { + param ( + [string]$ModuleName = '' + ) + # check if module is installed + $moduleInfo = Get-Module -ListAvailable -Name $ModuleName -ErrorAction SilentlyContinue + if ($moduleInfo) { return } + + Write-Host "${ModuleName} module not found." -ForegroundColor Red + Install-Module -Name $ModuleName -Scope CurrentUser + + Import-Module -Name $ModuleName +} + +Install-CustomModules -ModuleName 'tiPS' +Install-CustomModules -ModuleName 'PSScriptAnalyzer' +Install-CustomModules -ModuleName 'Terminal-Icons' +Install-CustomModules -ModuleName 'PSReadLine' +Install-CustomModules -ModuleName 'PSWindowsUpdate' + +# kali.omp.json +oh-my-posh --init --shell pwsh --config "$env:OneDrive\Documents\PowerShell\prompt\themes\stelbent-compact.minimal.omp.json" | Invoke-Expression + +Set-PSReadLineOption -PredictionSource History +Set-PSReadLineOption -PredictionViewStyle ListView +Set-PSReadLineOption -EditMode Windows +Set-PSReadLineKeyHandler -Key Tab -Function Complete + +Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() + $Local:word = $wordToComplete.Replace('"', '""') + $Local:ast = $commandAst.ToString().Replace('"', '""') + winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } +} +function Get-Ip-Address { + (Invoke-WebRequest -Uri ifconfig.me/ip).Content +} + +Set-Alias getIp Get-Ip-Address + +function Invoke-WslReboot() { + param ( + [string]$Distro = 'Debian' + ) + Write-Host "Rebooting $Distro" + wsl --shutdown +} + +Set-Alias wslreboot Invoke-WslReboot + +function Update-Budget() { + Write-Host "Updating budget database" + py D:\dev\export-budget-csv\export.py -s "$env:OneDrive\Documents\Financial\Wood Family Financials.xlsx" + Write-Host "Budget database updated" +} + +Set-Alias updbudget Update-Budget + +function Update-Winget() { + winget upgrade +} + +Set-Alias wgu Update-Winget +#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module + +Import-Module -Name Microsoft.WinGet.CommandNotFound +#f45873b3-b655-43a6-b217-97c00aa0db58 + +if (Get-Command zoxide -ErrorAction SilentlyContinue) { + Invoke-Expression (& { (zoxide init powershell | Out-String) }) +} +else { + Write-Host "zoxide command not found. Attempting to install via winget..." + try { + winget install -e --id ajeetdsouza.zoxide + Write-Host "zoxide installed successfully. Initializing..." + Invoke-Expression (& { (zoxide init powershell | Out-String) }) + } + catch { + Write-Error "Failed to install zoxide. Error: $_" + } +} + +Set-TiPSConfiguration -AutomaticallyWritePowerShellTip EverySession + +# Finds files recursively matching a pattern. +function ff($name) { + Get-ChildItem -Recurse -Filter "*${name}*" -ErrorAction SilentlyContinue | ForEach-Object { Write-Output "${$_.directory}\$(%_)" } +} + +# Creates an empty file (similar to the touch command in Linux). +function touch($file) { + "" | Out-File -File $file -Encoding ascii +} + +# Reloads the current profile. +function Update-Profile { + & $PROFILE +} + +# Checks for and updates PowerShell to the latest version. +function Update-PowerShell { + if (-not $global:canConnectToGitHub) { + Write-Host "Skipping PowerShell update check due to GitHub.com not responding within 1 second." -ForegroundColor Yellow + return + } + + try { + Write-Host "Checking for PowerShell updates..." -ForegroundColor Cyan + $updateNeeded = $false + $currentVersion = $PSVersionTable.PSVersion.ToString() + $gitHubApiUrl = "https://api.github.com/repos/PowerShell/PowerShell/releases/latest" + $latestReleaseInfo = Invoke-RestMethod -Uri $gitHubApiUrl + $latestVersion = $latestReleaseInfo.tag_name.Trim('v') + if ($currentVersion -lt $latestVersion) { + $updateNeeded = $true + } + + if ($updateNeeded) { + Write-Host "Updating PowerShell..." -ForegroundColor Yellow + winget upgrade "Microsoft.PowerShell" --accept-source-agreements --accept-package-agreements + Write-Host "PowerShell has been updated. Please restart your shell to reflect changes" -ForegroundColor Magenta + } + else { + Write-Host "Your PowerShell is up to date." -ForegroundColor Green + } + } + catch { + Write-Error "Failed to update PowerShell. Error: $_" + } +} +Update-PowerShell + +# Searches for a regular expression in files (similar to the grep command in Linux). +function grep($regex, $dir) { + if ( $dir ) { + Get-ChildItem $dir | select-string $regex + return + } + $input | select-string $regex +} + +# Displays disk volume information. +function df { + get-volume +} + +# Displays the first n lines of a file8587 +function head { + param($Path, $n = 10) + Get-Content $Path -Head $n +} + +# Displays the last n lines of a file +function tail { + param($Path, $n = 10) + Get-Content $Path -Tail $n +} + +# Navigates to the Documents directory. +function docs { Set-Location -Path $HOME\Documents } + +# Navigates to the Downloads directory. +function dl { Set-Location -Path $HOME\Downloads } + +# Clears the DNS client cache. +function flushdns { Clear-DnsClientCache } + +# Copies text to the clipboard. +function cpy { Set-Clipboard $args[0] } + +# Gets the text from the clipboard. +function pst { Get-Clipboard } + +# Enhanced PowerShell Experience +Set-PSReadLineOption -Colors @{ + Command = 'Yellow' + Parameter = 'Green' + String = 'DarkCyan' +} + +# http://bin.christitus.com/unakijolon \ No newline at end of file diff --git a/dotfiles/README.md b/dotfiles/README.md new file mode 100644 index 0000000..8327684 --- /dev/null +++ b/dotfiles/README.md @@ -0,0 +1,120 @@ + +# dotfiles + +My personal dotfiles and system setup configuration for Linux machines. + +## Quick Start + +To set up a new machine, run: + +```bash +curl -fsSL https://raw.githubusercontent.com/acedanger/shell/main/bootstrap.sh | bash +``` + +## What's Included + +### Package Managers +- [**Nala**](https://gitlab.com/volian/nala): A better front-end for `apt` with parallel downloads and improved interface +- [**VS Code**](https://code.visualstudio.com/): Microsoft's popular code editor +- [**GitHub CLI**](https://cli.github.com/): Official GitHub command-line tool + +### Core Packages +- [`git`](https://git-scm.com/): Version control +- [`python3`](https://www.python.org/): Python runtime +- [`wget`](https://www.gnu.org/software/wget/) & [`curl`](https://curl.se/): Download utilities +- [`bat`](https://github.com/sharkdp/bat): A better `cat` with syntax highlighting +- [`cowsay`](https://github.com/piuccio/cowsay): For fun CLI messages +- [`lolcat`](https://github.com/busyloop/lolcat): Colorful terminal output +- [`fzf`](https://github.com/junegunn/fzf): Fuzzy finder +- [`zsh`](https://www.zsh.org/): Better shell +- [`nala`](https://gitlab.com/volian/nala): Better package manager for Debian/Ubuntu + +### Shell Setup +- [**Oh My Zsh**](https://ohmyz.sh/): Framework for managing Zsh configuration +- [**Agnoster Theme**](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster): Beautiful terminal theme with Git integration + +#### Zsh Plugins +1. [`zsh-autosuggestions`](https://github.com/zsh-users/zsh-autosuggestions): Suggests commands as you type based on history +2. [`zsh-syntax-highlighting`](https://github.com/zsh-users/zsh-syntax-highlighting): Syntax highlighting for the shell +3. [`zsh-you-should-use`](https://github.com/MichaelAquilina/zsh-you-should-use): Reminds you of existing aliases +4. [`git`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git): Git integration and aliases +5. [`docker`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/docker): Docker commands integration +6. [`docker-compose`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/docker-compose): Docker Compose integration +7. [`z`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/z): Quick directory jumping +8. [`ssh`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/ssh): SSH configuration and shortcuts + +### Development Tools +- [**nvm**](https://github.com/nvm-sh/nvm): Node Version Manager for managing Node.js versions +- [**zoxide**](https://github.com/ajeetdsouza/zoxide): Smarter directory navigation (a modern replacement for `z`) +- [**Lazydocker**](https://github.com/jesseduffield/lazydocker): Terminal UI for Docker and Docker Compose, making container management easier +- [**VS Code**](https://code.visualstudio.com/): Code editor with essential extensions + +## Features + +### Automatic Setup +- Automatically installs and configures all necessary packages and tools +- Sets up Zsh as the default shell +- Configures Nala package manager with optimized mirrors +- Installs and configures Node.js LTS version via nvm +- Installs Lazydocker for Docker container management +- Sets up VS Code with recommended extensions + +### Dotfile Management +- Automatically symlinks all configuration files +- Manages Zsh configuration and plugins +- Sets up Git configuration +- Configures custom aliases and functions + +### Custom Configurations +- Terminal greeting with fortune and cowsay +- Optimized Zsh history settings +- Improved command-line navigation with zoxide +- Automatic Node.js version switching using .nvmrc + +## Installation Process + +1. The script will first set up necessary package repositories: + - Nala package manager + - VS Code + - GitHub CLI + +2. Install core packages using Nala for better performance + +3. Install special tools not available via apt: + - Lazydocker (Docker TUI manager) + +4. Set up the shell environment: + - Install Zsh and Oh My Zsh + - Configure Zsh plugins and themes + - Set up custom aliases and configurations + +5. Install development tools: + - Set up nvm and Node.js + - Configure zoxide for better navigation + - Install and configure Git + +## Manual Steps + +If you need to manually set up aliases: + +```sh +# Create new symlink +ln -s ~/shell/dotfiles/my-aliases.zsh ~/.oh-my-zsh/custom/aliases.zsh + +# If the symlink already exists, use -f to force creation +ln -sf ~/shell/dotfiles/my-aliases.zsh ~/.oh-my-zsh/custom/aliases.zsh +``` + +## Post-Installation + +After installation: +1. Start a new terminal session or run `zsh` +2. The shell will be configured with all plugins and settings +3. You can start using all installed tools and aliases + +## Maintenance + +To update your setup: +1. Pull the latest changes from the repository +2. Run the setup script again - it's designed to be idempotent +3. Start a new shell session to apply any changes diff --git a/dotfiles/my-aliases.zsh b/dotfiles/my-aliases.zsh new file mode 100644 index 0000000..9310f67 --- /dev/null +++ b/dotfiles/my-aliases.zsh @@ -0,0 +1,14 @@ +alias py=python3 +alias gp="git pull" +alias gpush="git push" +alias gc="git commit" +alias gcm="git commit -m" + +alias ll="ls -laFh --group-directories-first --color=auto" +alias findzombie="ps -A -ostat,pid,ppid | grep -e '[zZ]'" +alias plex="/home/acedanger/shell/plex.sh" +alias update="/home/acedanger/shell/update.sh" +alias dcdn="docker compose down" +alias dcupd="docker compose up -d" +alias lzd="lazydocker" +alias cat="batcat" diff --git a/dotfiles/tailscale-acl.json b/dotfiles/tailscale-acl.json new file mode 100644 index 0000000..e63566b --- /dev/null +++ b/dotfiles/tailscale-acl.json @@ -0,0 +1,59 @@ +// Example/default ACLs for unrestricted connections. +{ + // Define access control lists for users, groups, autogroups, tags, + // Tailscale IP addresses, and subnet ranges. + "acls": [ + { + "action": "accept", + "src": ["tag:client", "tag:server", "acedanger49@gmail.com"], + "dst": ["tag:golink:*", "tag:server:*"], + }, + // Allow all connections. + // Comment this section out if you want to define specific restrictions. + {"action": "accept", "src": ["*"], "dst": ["*:*"]}, + ], + + // Define users and devices that can use Tailscale SSH. + "ssh": [ + { + // any user can use Tailscale SSH to connect to their own devices + // in check mode as a root or non-root user + "action": "accept", + "src": ["tag:client", "tag:server", "acedanger49@gmail.com"], + "dst": ["tag:server"], + "users": ["autogroup:nonroot", "root"], + }, + { + // any user can use Tailscale SSH to connect to their own devices + // in check mode as a root or non-root user + "action": "check", + "src": ["autogroup:member"], + "dst": ["autogroup:self"], + "users": ["autogroup:nonroot", "root"], + }, + ], + + "nodeAttrs": [ + { + // Funnel policy, which lets tailnet members control Funnel + // for their own devices. + // Learn more at https://tailscale.com/kb/1223/tailscale-funnel/ + "target": ["autogroup:member"], + "attr": ["funnel"], + }, + {"target": ["*"], "app": {"tailscale.com/app-connectors": []}}, + ], + + // Define the tags which can be applied to devices and by which users. + "tagOwners": { + "tag:golink": ["acedanger49@gmail.com"], + "tag:server": ["acedanger49@gmail.com"], + "tag:client": ["acedanger49@gmail.com"], + "tag:docker": ["acedanger49@gmail.com"], + }, + + "autoapprovers": { + "exitNode": ["autogroup:admin"], + }, + // Test access rules every time they're saved. +} diff --git a/setup/packages.list b/setup/packages.list new file mode 100644 index 0000000..e3183fe --- /dev/null +++ b/setup/packages.list @@ -0,0 +1,10 @@ +git +python3 +wget +curl +bat +cowsay +lolcat +fzf +zsh +nala \ No newline at end of file diff --git a/setup/setup.sh b/setup/setup.sh new file mode 100755 index 0000000..d5fd5ce --- /dev/null +++ b/setup/setup.sh @@ -0,0 +1,158 @@ +#!/bin/bash + +set -e +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +DOTFILES_DIR="$(dirname "$SCRIPT_DIR")" +DOTFILES_SUBDIR="$DOTFILES_DIR/dotfiles" + +# Colors for output +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +echo -e "${GREEN}Starting system setup...${NC}" + +# Add apt repositories +echo -e "${YELLOW}Setting up apt repositories...${NC}" + +# Install prerequisites +sudo apt-get install -y wget gpg apt-transport-https + +# Setup Nala repository +echo -e "${YELLOW}Setting up Nala repository...${NC}" +curl -fsSL https://deb.volian.org/volian/scar.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/volian-archive-scar.gpg +echo "deb [arch=$(dpkg --print-architecture)] https://deb.volian.org/volian/ scar main" | sudo tee /etc/apt/sources.list.d/volian-archive-scar.list > /dev/null + +# Setup VS Code repository +echo -e "${YELLOW}Setting up VS Code repository...${NC}" +wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/packages.microsoft.gpg +sudo install -D -o root -g root -m 644 /tmp/packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg +sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' +rm /tmp/packages.microsoft.gpg + +# Setup GitHub CLI repository +echo -e "${YELLOW}Setting up GitHub CLI repository...${NC}" +sudo mkdir -p -m 755 /etc/apt/keyrings +out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \ + && sudo install -D -o root -g root -m 644 "$out" /etc/apt/keyrings/githubcli-archive-keyring.gpg \ + && rm "$out" \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null + +# Update package lists +sudo apt update + +# Install Nala first +echo -e "${YELLOW}Installing Nala package manager...${NC}" +sudo apt-get install -y nala + +# Configure Nala mirrors +echo -e "${YELLOW}Configuring Nala mirrors...${NC}" +sudo nala fetch --auto --fetches 3 + +# Install remaining packages using Nala +echo -e "${YELLOW}Installing packages from packages.list...${NC}" +mapfile -t pkgs < <(grep -v '^//' "$SCRIPT_DIR/packages.list" | grep -v -e '^$' -e '^nala$') +sudo nala install -y "${pkgs[@]}" + +# Install Zsh if not already installed +echo -e "${YELLOW}Installing Zsh...${NC}" +if ! command -v zsh &> /dev/null; then + sudo apt-get install -y zsh +fi + +# Install Oh My Zsh +echo -e "${YELLOW}Installing Oh My Zsh...${NC}" +if [ ! -d "$HOME/.oh-my-zsh" ]; then + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended +else + echo "Oh My Zsh already installed" +fi + +# Install zoxide +echo -e "${YELLOW}Installing zoxide...${NC}" +if ! command -v zoxide &> /dev/null; then + curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash + + # Ensure .local/bin is in PATH + if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then + echo 'export PATH="$PATH:$HOME/.local/bin"' >> "$HOME/.bashrc" + export PATH="$PATH:$HOME/.local/bin" + fi +fi + +# Install nvm (Node Version Manager) +echo -e "${YELLOW}Installing nvm...${NC}" +if [ ! -d "$HOME/.nvm" ]; then + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash +fi + +# Load nvm regardless of whether it was just installed or already existed +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" + +# Install and set up Node.js only if nvm is available +if command -v nvm &>/dev/null; then + # Install latest LTS version of Node.js + nvm install --lts + nvm use --lts + # Set the LTS version as default + nvm alias default 'lts/*' +else + echo -e "${YELLOW}Warning: nvm installation may require a new shell session${NC}" +fi + +# Install Lazydocker (not available in apt repositories) +echo -e "${YELLOW}Installing Lazydocker...${NC}" +if ! command -v lazydocker &> /dev/null; then + LAZYDOCKER_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazydocker/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') + curl -Lo lazydocker.tar.gz "https://github.com/jesseduffield/lazydocker/releases/latest/download/lazydocker_${LAZYDOCKER_VERSION}_Linux_x86_64.tar.gz" + mkdir -p lazydocker-temp + tar xf lazydocker.tar.gz -C lazydocker-temp + sudo mv lazydocker-temp/lazydocker /usr/local/bin + rm -rf lazydocker-temp lazydocker.tar.gz + echo -e "${GREEN}Lazydocker installed successfully!${NC}" +else + echo -e "Lazydocker is already installed" +fi + +# Install Zsh plugins +echo -e "${YELLOW}Installing Zsh plugins...${NC}" +ZSH_CUSTOM="$HOME/.oh-my-zsh/custom" +PLUGINS_DIR="$ZSH_CUSTOM/plugins" + +# zsh-autosuggestions +if [ ! -d "$PLUGINS_DIR/zsh-autosuggestions" ]; then + git clone https://github.com/zsh-users/zsh-autosuggestions "$PLUGINS_DIR/zsh-autosuggestions" +fi + +# zsh-syntax-highlighting +if [ ! -d "$PLUGINS_DIR/zsh-syntax-highlighting" ]; then + git clone https://github.com/zsh-users/zsh-syntax-highlighting "$PLUGINS_DIR/zsh-syntax-highlighting" +fi + +# zsh-you-should-use +if [ ! -d "$PLUGINS_DIR/zsh-you-should-use" ]; then + git clone https://github.com/MichaelAquilina/zsh-you-should-use "$PLUGINS_DIR/zsh-you-should-use" +fi + +# Set up dotfiles +echo -e "${YELLOW}Setting up dotfiles...${NC}" +# Set up Oh My Zsh custom directory and aliases +ZSH_CUSTOM="$HOME/.oh-my-zsh/custom" +mkdir -p "$ZSH_CUSTOM" +ln -sf "$DOTFILES_SUBDIR/my-aliases.zsh" "$ZSH_CUSTOM/aliases.zsh" + +# Set up dotfiles in home directory +ln -sf "$DOTFILES_SUBDIR/.zshrc" "$HOME/.zshrc" +ln -sf "$DOTFILES_SUBDIR/.nanorc" "$HOME/.nanorc" 2>/dev/null || true +ln -sf "$DOTFILES_SUBDIR/.profile" "$HOME/.profile" 2>/dev/null || true +ln -sf "$DOTFILES_SUBDIR/.gitconfig" "$HOME/.gitconfig" 2>/dev/null || true + +# Set Zsh as default shell if not already set +if [[ "$SHELL" != *"zsh"* ]]; then + echo -e "${YELLOW}Setting Zsh as default shell...${NC}" + chsh -s $(which zsh) +fi + +echo -e "${GREEN}Setup completed successfully!${NC}"