283 lines
9.3 KiB
Nix
283 lines
9.3 KiB
Nix
{
|
|
config,
|
|
...
|
|
}:
|
|
|
|
{
|
|
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
|
|
|
|
# Set various environment variables
|
|
export NIXPKGS_ALLOW_INSECURE=1
|
|
export NIXPKGS_ALLOW_UNFREE=1
|
|
export DOTFILES_PATH="${config.home.homeDirectory}/.dotfiles"
|
|
export EDITOR="code --wait"
|
|
export STARSHIP_ENABLE_RIGHT_PROMPT="true"
|
|
export STARSHIP_ENABLE_BASH_COMPLETION="true"
|
|
export XDG_DATA_DIRS="/usr/share:/var/lib/flatpak/exports/share:${config.home.homeDirectory}/.local/share/flatpak/exports/share"
|
|
export BUN_INSTALL="$HOME/.bun"
|
|
|
|
# Source .profile (If exists)
|
|
if [ -f "${config.home.homeDirectory}/.profile" ]; then
|
|
source "${config.home.homeDirectory}/.profile"
|
|
fi
|
|
|
|
# Source .bashrc.local (If exists)
|
|
if [ -f "${config.home.homeDirectory}/.bashrc.local" ]; then
|
|
source "${config.home.homeDirectory}/.bashrc.local"
|
|
fi
|
|
|
|
# Homebrew (if installed)
|
|
if [ -d /home/linuxbrew/.linuxbrew ]; then
|
|
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
|
fi
|
|
|
|
# PyEnv (if installed)
|
|
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
|
|
|
|
# NVM (if installed)
|
|
if [ -d "$HOME/.nvm" ]; then
|
|
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
|
|
fi
|
|
|
|
# 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'
|
|
alias ssh-add="ssh-add.exe"
|
|
alias git="git.exe"
|
|
fi
|
|
|
|
# Set SSH_AUTH_SOCK to 1Password agent if not already set
|
|
# Also block /run/user/1000/gnupg/S.gpg-agent.ssh and override with 1Password
|
|
if [ -z "$SSH_AUTH_SOCK" ] || [[ "$SSH_AUTH_SOCK" == *"gnupg/S.gpg-agent.ssh"* ]]; 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 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
|
|
|
|
# Display welcome message for interactive shells
|
|
if [ -t 1 ]; then
|
|
command -v helloworld &> /dev/null && helloworld
|
|
fi
|
|
'';
|
|
|
|
# Shell aliases
|
|
shellAliases = {
|
|
# 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 --";
|
|
|
|
# SSH alias
|
|
"ssh" = "${config.home.homeDirectory}/.local/bin/smart-ssh";
|
|
|
|
# Utility aliases
|
|
"random" = "openssl rand -base64";
|
|
|
|
# Folder navigation
|
|
".." = "cd ..";
|
|
"..." = "cd ../..";
|
|
"...." = "cd ../../..";
|
|
};
|
|
|
|
# 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:${config.home.homeDirectory}/.dotfiles/bin"
|
|
export PATH="/usr/bin:$PATH"
|
|
export PATH="$BUN_INSTALL/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
|
|
|
|
# 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
|
|
|
|
# Japanese input
|
|
export GTK_IM_MODULE=fcitx5
|
|
export QT_IM_MODULE=fcitx5
|
|
export XMODIFIERS="@im=fcitx5"
|
|
'';
|
|
|
|
# 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'"
|
|
];
|
|
};
|
|
|
|
}
|