mirror of
https://github.com/itme-brain/nixos.git
synced 2026-03-24 08:39:42 -04:00
v2
This commit is contained in:
parent
036db0b3b9
commit
203170a88f
66 changed files with 169 additions and 54 deletions
3
src/user/modules/bash/config/alias.nix
Normal file
3
src/user/modules/bash/config/alias.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
cd = "cd -L";
|
||||
}
|
||||
2
src/user/modules/bash/config/bashprofile.nix
Normal file
2
src/user/modules/bash/config/bashprofile.nix
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
''
|
||||
''
|
||||
63
src/user/modules/bash/config/bashrc.nix
Normal file
63
src/user/modules/bash/config/bashrc.nix
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
''
|
||||
export DIRENV_LOG_FORMAT=
|
||||
|
||||
function cdg() {
|
||||
if [[ $1 == "--help" ]]; then
|
||||
echo "A simple utility for navigating to the root of a git repo"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check for invalid command
|
||||
if [[ -n "$1" ]]; then
|
||||
echo "Invalid command: $1. Try 'cdg --help'."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local root_dir
|
||||
root_dir=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||
local git_status=$?
|
||||
|
||||
if [ $git_status -ne 0 ]; then
|
||||
echo "Error: Not a git repo."
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd "$root_dir"
|
||||
}
|
||||
|
||||
function penpot() {
|
||||
case "$1" in
|
||||
run)
|
||||
sudo docker compose -p penpot -f ~/Documents/tools/penpot/docker-compose.yaml up -d >/dev/null 2>&1
|
||||
nohup bash -c '(sleep 10 && if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
xdg-open "http://localhost:9001"
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
open "http://localhost:9001"
|
||||
fi)' >/dev/null 2>&1 &
|
||||
echo "Started penpot on http://localhost:9001"
|
||||
;;
|
||||
stop)
|
||||
echo "Stopping penpot"
|
||||
sudo docker compose -p penpot -f ~/Documents/tools/penpot/docker-compose.yaml down >/dev/null 2>&1
|
||||
;;
|
||||
update)
|
||||
sudo docker compose -f ~/Documents/tools/penpot/docker-compose.yaml pull
|
||||
echo "Updated penpot!"
|
||||
;;
|
||||
help)
|
||||
xdg-open "https://help.penpot.app/"
|
||||
echo "Opened penpot help page in your browser."
|
||||
;;
|
||||
*)
|
||||
echo "Usage: penpot {run|stop|update|help}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
source ~/Documents/projects/ldv/ldv.sh
|
||||
|
||||
set -o vi
|
||||
|
||||
bind 'set completion-ignore-case on'
|
||||
bind 'set completion-map-case on'
|
||||
''
|
||||
103
src/user/modules/bash/config/prompt.nix
Normal file
103
src/user/modules/bash/config/prompt.nix
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
''
|
||||
check_ssh() {
|
||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
ssh_PS1="\n\[\033[01;37m\]\u@\h:\[\033[00m\]"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
add_icon() {
|
||||
local icon=$1
|
||||
if [[ ! $venv_icons =~ $icon ]]; then
|
||||
venv_icons+="$icon"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_icon() {
|
||||
local icon=$1
|
||||
venv_icons=''${venv_icons//$icon/}
|
||||
}
|
||||
|
||||
python_icon="\[\033[01;33m\]\[\033[00m\]"
|
||||
node_icon="\[\033[01;93m\]\[\033[00m\]"
|
||||
nix_icon="\[\033[01;34m\]\[\033[00m\]"
|
||||
|
||||
check_venv() {
|
||||
if [ -n "$IN_NIX_SHELL" ]; then
|
||||
add_icon "$nix_icon"
|
||||
else
|
||||
remove_icon "$nix_icon"
|
||||
fi
|
||||
|
||||
if [ -n "$VIRTUAL_ENV" ]; then
|
||||
add_icon "$python_icon"
|
||||
else
|
||||
remove_icon "$python_icon"
|
||||
fi
|
||||
|
||||
if [ -d "''${git_root}/node_modules" ]; then
|
||||
add_icon "$node_icon"
|
||||
else
|
||||
remove_icon "$node_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
set_git_dir() {
|
||||
local superproject_root=$(git rev-parse --show-superproject-working-tree 2>/dev/null)
|
||||
if [[ -n "$superproject_root" ]]; then
|
||||
# If inside a submodule, display only the root of the parent and the submodule name
|
||||
local submodule_name=$(basename "$git_root")
|
||||
|
||||
working_dir="\[\033[01;34m\] ''${superproject_root##*/}/$submodule_name$git_curr_dir\[\033[00m\]"
|
||||
elif [ "$git_curr_dir" == "." ]; then
|
||||
working_dir="\[\033[01;34m\] $git_root_dir\[\033[00m\]"
|
||||
return 0
|
||||
else
|
||||
working_dir="\[\033[01;34m\] $git_root_dir$git_curr_dir\[\033[00m\]"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
relative_path() {
|
||||
local absolute_target=$(readlink -f "$1")
|
||||
local absolute_base=$(readlink -f "$2")
|
||||
echo "''${absolute_target#$absolute_base}"
|
||||
}
|
||||
|
||||
check_project() {
|
||||
local git_root=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||
|
||||
if [ -n "$git_root" ]; then
|
||||
local git_branch=$(git branch --show-current 2>/dev/null)
|
||||
git_branch=''${git_branch:-$(git rev-parse --short HEAD 2>/dev/null)}
|
||||
|
||||
local git_curr_dir=$(relative_path "." "$git_root")
|
||||
local git_root_dir=$(basename "$git_root")
|
||||
|
||||
git_branch_PS1="\[\033[01;31m\]$git_branch :\[\033[00m\]"
|
||||
|
||||
set_git_dir
|
||||
check_venv
|
||||
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function set_prompt() {
|
||||
local green_arrow="\[\033[01;32m\]>> "
|
||||
local white_text="\[\033[00m\]"
|
||||
local working_dir="\[\033[01;34m\]\w\[\033[00m\]"
|
||||
|
||||
local ssh_PS1
|
||||
local venv_icons
|
||||
local git_branch_PS1
|
||||
|
||||
check_ssh
|
||||
check_project
|
||||
|
||||
PS1="$ssh_PS1\n$working_dir\n$venv_icons$green_arrow$git_branch_PS1$white_text"
|
||||
return 0
|
||||
}
|
||||
|
||||
PROMPT_COMMAND="set_prompt"
|
||||
''
|
||||
33
src/user/modules/bash/default.nix
Normal file
33
src/user/modules/bash/default.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{ lib, config, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
cfg = config.modules.bash;
|
||||
|
||||
in
|
||||
{ options.modules.bash = { enable = mkEnableOption "bash"; };
|
||||
config = mkIf cfg.enable {
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
|
||||
initExtra = import ./config/prompt.nix;
|
||||
profileExtra = import ./config/bashprofile.nix;
|
||||
bashrcExtra = import ./config/bashrc.nix;
|
||||
shellAliases = import ./config/alias.nix;
|
||||
};
|
||||
|
||||
programs = {
|
||||
direnv = {
|
||||
enable = true;
|
||||
enableBashIntegration = true;
|
||||
nix-direnv.enable = true;
|
||||
};
|
||||
ripgrep.enable = true;
|
||||
lsd = {
|
||||
enable = true;
|
||||
enableAliases = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue