refactor
This commit is contained in:
271
config/bash.nix
Normal file
271
config/bash.nix
Normal file
@@ -0,0 +1,271 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
{
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
|
||||
# History configuration
|
||||
historySize = 1000;
|
||||
historyFileSize = 2000;
|
||||
historyControl = [ "ignoredups" "ignorespace" ];
|
||||
|
||||
# Bash options and extra configuration
|
||||
bashrcExtra = ''
|
||||
# Set various bash options
|
||||
shopt -s histappend
|
||||
shopt -s checkwinsize
|
||||
shopt -s cdspell
|
||||
shopt -s cmdhist
|
||||
shopt -s dotglob
|
||||
shopt -s expand_aliases
|
||||
shopt -s extglob
|
||||
shopt -s histreedit
|
||||
shopt -s histverify
|
||||
shopt -s no_empty_cmd_completion
|
||||
shopt -s nocaseglob
|
||||
|
||||
# Detect distribution and set CGO_CFLAGS for Pop!_OS
|
||||
if [ -f /etc/os-release ]; then
|
||||
distro=$(awk -F= '/^NAME/{print $2}' /etc/os-release | tr -d '"')
|
||||
if [[ "$distro" == *"Pop!_OS"* ]]; then
|
||||
export CGO_CFLAGS="-I/usr/include"
|
||||
fi
|
||||
fi
|
||||
|
||||
# WSL2 specific configuration
|
||||
if [[ "$(uname -a)" == *"microsoft-standard-WSL2"* ]]; then
|
||||
[ -f "${config.home.homeDirectory}/.agent-bridge.sh" ] && source "${config.home.homeDirectory}/.agent-bridge.sh"
|
||||
alias winget='winget.exe'
|
||||
fi
|
||||
|
||||
# Set SSH_AUTH_SOCK to 1Password agent if not already set
|
||||
if [ -z "$SSH_AUTH_SOCK" ]; then
|
||||
export SSH_AUTH_SOCK=~/.1password/agent.sock
|
||||
fi
|
||||
|
||||
# Set Chrome executable to Brave if available
|
||||
if command -v brave-browser &> /dev/null; then
|
||||
export CHROME_EXECUTABLE=/usr/bin/brave-browser
|
||||
fi
|
||||
|
||||
# Source 1Password plugins if available
|
||||
if [ -f ${config.home.homeDirectory}/.config/op/plugins.sh ]; then
|
||||
source ${config.home.homeDirectory}/.config/op/plugins.sh
|
||||
fi
|
||||
|
||||
# Read 1Password service account token
|
||||
if [ -f ~/.op_sat ]; then
|
||||
export OP_SERVICE_ACCOUNT_TOKEN=$(cat ~/.op_sat)
|
||||
|
||||
# Security checks for .op_sat file
|
||||
if [ "$(stat -c %a ~/.op_sat)" != "600" ]; then
|
||||
echo "WARNING: ~/.op_sat is not 0600, please fix this!"
|
||||
fi
|
||||
|
||||
if [ "$(stat -c %U ~/.op_sat)" != "$(whoami)" ]; then
|
||||
echo "WARNING: ~/.op_sat is not owned by the current user, please fix this!"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Source nix home-manager session variables
|
||||
if [ -f "${config.home.homeDirectory}/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
|
||||
. "${config.home.homeDirectory}/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
||||
fi
|
||||
|
||||
# Source ble.sh if available and configure fzf history search
|
||||
if [[ -f "${config.home.homeDirectory}/.nix-profile/share/blesh/ble.sh" ]]; then
|
||||
source "${config.home.homeDirectory}/.nix-profile/share/blesh/ble.sh"
|
||||
|
||||
# Custom function for fzf history search
|
||||
function fzf_history_search() {
|
||||
local selected
|
||||
selected=$(history | fzf --tac --height=40% --layout=reverse --border --info=inline \
|
||||
--query="$READLINE_LINE" \
|
||||
--color 'fg:#ebdbb2,bg:#282828,hl:#fabd2f,fg+:#ebdbb2,bg+:#3c3836,hl+:#fabd2f' \
|
||||
--color 'info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,header:#665c54' \
|
||||
| sed 's/^ *[0-9]* *//')
|
||||
if [[ -n "$selected" ]]; then
|
||||
READLINE_LINE="$selected"
|
||||
READLINE_POINT=$${#selected}
|
||||
fi
|
||||
ble-redraw-prompt
|
||||
}
|
||||
|
||||
# Bind Ctrl+R to custom fzf function
|
||||
bind -x '"\C-r": fzf_history_search'
|
||||
fi
|
||||
|
||||
# Source local bashrc if it exists
|
||||
if [ -f "${config.home.homeDirectory}/.bashrc.local" ]; then
|
||||
source "${config.home.homeDirectory}/.bashrc.local"
|
||||
fi
|
||||
|
||||
# Display welcome message for interactive shells
|
||||
if [ -t 1 ]; then
|
||||
command -v helloworld &> /dev/null && helloworld
|
||||
fi
|
||||
'';
|
||||
|
||||
# Shell aliases
|
||||
shellAliases = {
|
||||
# Folder navigation
|
||||
"." = "cd .";
|
||||
".." = "cd ..";
|
||||
"..." = "cd ../..";
|
||||
"...." = "cd ../../..";
|
||||
"....." = "cd ../../../..";
|
||||
|
||||
# Docker Compose alias (for old scripts)
|
||||
"docker-compose" = "docker compose";
|
||||
|
||||
# Modern tools aliases
|
||||
"l" = "eza --header --long --git --group-directories-first --group --icons --color=always --sort=name --hyperlink -o --no-permissions";
|
||||
"ll" = "l";
|
||||
"la" = "l -a";
|
||||
"cat" = "bat";
|
||||
"du" = "dust";
|
||||
"df" = "duf";
|
||||
"augp" = "sudo apt update && sudo apt upgrade -y && sudo apt autopurge -y && sudo apt autoclean";
|
||||
|
||||
# Docker aliases
|
||||
"d" = "docker";
|
||||
"dc" = "docker compose";
|
||||
"dce" = "docker compose exec";
|
||||
"dcl" = "docker compose logs";
|
||||
"dcd" = "docker compose down";
|
||||
"dcu" = "docker compose up";
|
||||
"dcp" = "docker compose ps";
|
||||
"dcps" = "docker compose ps";
|
||||
"dcpr" = "dcp && dcd && dcu -d && dcl -f";
|
||||
"dcr" = "dcd && dcu -d && dcl -f";
|
||||
"ddpul" = "docker compose down && docker compose pull && docker compose up -d && docker compose logs -f";
|
||||
"docker-nuke" = "docker kill $(docker ps -q) && docker rm $(docker ps -a -q) && docker system prune --all --volumes --force && docker volume prune --force";
|
||||
|
||||
# Git aliases
|
||||
"g" = "git";
|
||||
"gg" = "git pull";
|
||||
"gl" = "git log --stat";
|
||||
"gp" = "git push";
|
||||
"gs" = "git status -s";
|
||||
"gst" = "git status";
|
||||
"ga" = "git add";
|
||||
"gc" = "git commit";
|
||||
"gcm" = "git commit -m";
|
||||
"gco" = "git checkout";
|
||||
"gcb" = "git checkout -b";
|
||||
|
||||
# Kubernetes aliases
|
||||
"kubectl" = "minikube kubectl --";
|
||||
|
||||
# Editor aliases
|
||||
"zeditor" = "${config.home.homeDirectory}/.local/bin/zed";
|
||||
"zed" = "${config.home.homeDirectory}/.local/bin/zed";
|
||||
|
||||
# SSH alias
|
||||
"ssh" = "${config.home.homeDirectory}/.local/bin/smart-ssh";
|
||||
|
||||
# Utility aliases
|
||||
"random" = "openssl rand -base64";
|
||||
};
|
||||
|
||||
# Session variables
|
||||
sessionVariables = {
|
||||
# Basic environment
|
||||
DOTFILES_PATH = "${config.home.homeDirectory}/.dotfiles";
|
||||
|
||||
# Nix configuration
|
||||
NIXPKGS_ALLOW_UNFREE = "1";
|
||||
NIXPKGS_ALLOW_INSECURE = "1";
|
||||
|
||||
# XDG configuration
|
||||
XDG_DATA_DIRS = "$XDG_DATA_DIRS:/usr/share:/var/lib/flatpak/exports/share:$HOME/.local/share/flatpak/exports/share";
|
||||
|
||||
# Starship configuration
|
||||
STARSHIP_ENABLE_RIGHT_PROMPT = "true";
|
||||
STARSHIP_ENABLE_BASH_CONTINUATION = "true";
|
||||
};
|
||||
|
||||
# Profile extra (runs for login shells)
|
||||
profileExtra = ''
|
||||
# PATH manipulation
|
||||
export PATH="$PATH:${config.home.homeDirectory}/.local/bin"
|
||||
export PATH="$PATH:${config.home.homeDirectory}/.cargo/bin"
|
||||
export PATH="$PATH:$DOTFILES_PATH/bin"
|
||||
export PATH="/usr/bin:$PATH"
|
||||
|
||||
# PKG_CONFIG_PATH
|
||||
if [ -d /usr/lib/pkgconfig ]; then
|
||||
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH
|
||||
fi
|
||||
|
||||
# Spicetify
|
||||
if [ -d "${config.home.homeDirectory}/.spicetify" ]; then
|
||||
export PATH="$PATH:${config.home.homeDirectory}/.spicetify"
|
||||
fi
|
||||
|
||||
# Pyenv
|
||||
if [ -d "${config.home.homeDirectory}/.pyenv" ]; then
|
||||
export PYENV_ROOT="${config.home.homeDirectory}/.pyenv"
|
||||
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
|
||||
eval "$(pyenv init - bash)"
|
||||
fi
|
||||
|
||||
# pnpm
|
||||
if [ -d "${config.home.homeDirectory}/.local/share/pnpm" ]; then
|
||||
export PATH="$PATH:${config.home.homeDirectory}/.local/share/pnpm"
|
||||
fi
|
||||
|
||||
# Miniconda
|
||||
export PATH="${config.home.homeDirectory}/miniconda3/bin:$PATH"
|
||||
|
||||
# Flutter
|
||||
if [ -d "${config.home.homeDirectory}/.flutter/flutter/bin" ]; then
|
||||
export PATH="$PATH:${config.home.homeDirectory}/.flutter/flutter/bin"
|
||||
export PATH="$PATH:${config.home.homeDirectory}/.pub-cache/bin"
|
||||
|
||||
# Flutter Linux fixes
|
||||
export CPPFLAGS="-I/usr/include"
|
||||
export LDFLAGS="-L/usr/lib/x86_64-linux-gnu -lbz2"
|
||||
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH
|
||||
fi
|
||||
|
||||
# Tradaware / DiscountOffice Configuration
|
||||
if [ -d "${config.home.homeDirectory}/Projects/Work" ]; then
|
||||
export TRADAWARE_DEVOPS=true
|
||||
fi
|
||||
'';
|
||||
|
||||
# Interactive shell specific configuration
|
||||
initExtra = ''
|
||||
# Override ls with l only for interactive shells
|
||||
if [ -t 1 ]; then
|
||||
alias ls='l'
|
||||
fi
|
||||
|
||||
# Initialize starship prompt if available
|
||||
if command -v starship &> /dev/null; then
|
||||
eval "$(starship init bash)"
|
||||
else
|
||||
echo "FYI, starship not found"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
# Configure fzf
|
||||
programs.fzf = {
|
||||
enable = true;
|
||||
enableBashIntegration = true;
|
||||
defaultCommand = "fd --type f";
|
||||
defaultOptions = [
|
||||
"--height 40%"
|
||||
"--layout=reverse"
|
||||
"--border"
|
||||
"--inline-info"
|
||||
"--color 'fg:#ebdbb2,bg:#282828,hl:#fabd2f,fg+:#ebdbb2,bg+:#3c3836,hl+:#fabd2f'"
|
||||
"--color 'info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,header:#665c54'"
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user