Skip to content

Commit

Permalink
fix: improvements to install_packages.sh, enable bells in tmux, add f…
Browse files Browse the repository at this point in the history
…ish cd-override with check_and_activate_venv
  • Loading branch information
ErikBjare committed Sep 10, 2024
1 parent 297c77c commit a286815
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 15 deletions.
2 changes: 2 additions & 0 deletions home/.config/fish/config.fish
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,5 @@ if status is-interactive
# if atuin is installed, load it
type -q atuin > /dev/null; and atuin init fish --disable-up-arrow | source
end
# Run venv check on shell start
check_and_activate_venv
7 changes: 7 additions & 0 deletions home/.config/fish/functions/cd.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function cd
# Call the builtin cd function
builtin cd $argv

# After changing directory, check and activate venv if necessary
check_and_activate_venv
end
49 changes: 49 additions & 0 deletions home/.config/fish/functions/check_and_activate_venv.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function check_and_activate_venv --description 'Check for venv or Poetry env and activate if found' --on-variable PWD
# Guard against multiple executions
if set -q __VENV_ACTIVATION_IN_PROGRESS
return
end
set -g __VENV_ACTIVATION_IN_PROGRESS 1

set -l venv_dir
set -l poetry_env
set -l current_venv $VIRTUAL_ENV
set -l current_dir $PWD

# Check current directory and its parents for venv or pyproject.toml
set -l check_dir $current_dir
while test "$check_dir" != "/"
if test -d "$check_dir/venv"
set venv_dir "$check_dir/venv"
break
else if test -f "$check_dir/pyproject.toml"
set poetry_env (cd "$check_dir" && poetry env info --path 2>/dev/null)
break
end
set check_dir (dirname "$check_dir")
end

# Determine the new environment
set -l new_env
if test -n "$venv_dir"
set new_env "$venv_dir"
else if test -n "$poetry_env"
set new_env "$poetry_env"
end

# Check if we need to change the environment
if test -n "$new_env" -a "$new_env" != "$current_venv"
if test -n "$current_venv"
echo "Deactivating current environment: $current_venv"
deactivate
end
echo "Activating environment: $new_env"
source "$new_env/bin/activate.fish"
else if test -z "$new_env" -a -n "$current_venv"
echo "Deactivating environment: $current_venv"
deactivate
end

# Clean up
set -e __VENV_ACTIVATION_IN_PROGRESS
end
4 changes: 2 additions & 2 deletions home/.config/i3status/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ general {
interval = 1
}

order += "battery 0"
#order += "battery 0"
order += "load"
order += "cpu_usage"
#order += "cpu_temperature 0"
order += "disk /"
#order += "disk /tank"
#order += "disk /fast"
# Crashes for some reason... maybe pipewire's fault?
order += "volume master"
#order += "volume master"
#order += "volume mic" # Doesn't work...

# Network
Expand Down
2 changes: 1 addition & 1 deletion home/.gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#plus-color = "#012800"
#minus-color = "#340001"

[delta "decorations"]
[delta "decorations"]
commit-decoration-style = bold yellow box ul
file-style = bold yellow ul
file-decoration-style = none
Expand Down
5 changes: 5 additions & 0 deletions home/.tmux/master.conf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ set-option -g display-time 2500
# Set window names manually
set-option -g allow-rename off

# Set bells
set -g monitor-bell on
set -g visual-bell on
set -g bell-action other

# Basic theme (deprecated options)
#set-option -g message-fg white
#set-option -g message-bg blue
Expand Down
30 changes: 18 additions & 12 deletions install-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function ask() {
fi
}

# platform-independent
PIPX_PACKAGES="autoimport isort reorder-python-imports"

# if macOS
if (uname | grep 'Darwin'); then
echo 'Detected macOS'
Expand All @@ -37,20 +40,13 @@ if (uname | grep 'Darwin'); then
LIBS_PACKAGES="hdf5 c-blosc"
GIT_PACKAGES="git git-delta git-annex rclone git-annex-remote-rclone git-lfs"
BREW_CASK_PACKAGES="alacritty discord font-fira-code standard-notes zerotier-one visual-studio-code logseq koekeishiya/formulae/yabai flutter"
PIPX_PACKAGES="poetry powerline-status"
PIPX_PACKAGES="poetry powerline-status $PIPX_PACKAGES"

ask "Want to install brew packages?"
if [ $? -eq 0 ]; then
brew install $GNU_UTILS $BREW_PACKAGES $GIT_PACKAGES $LIBS_PACKAGES
brew install --cask $BREW_CASK_PACKAGES
fi

ask "Want to install pipx packages?"
if [ $? -eq 0 ]; then
for package in $PIPX_PACKAGES; do
pipx install $package
done
fi
elif (lsb_release -a | grep 'Arch Linux'); then
echo 'Detected Arch Linux'

Expand All @@ -65,12 +61,15 @@ elif (lsb_release -a | grep 'Arch Linux'); then
NODE="nodejs"
TEX="texlive-core"
X11="xclip xorg-xkill"
MISC="playerctl age"
MISC="playerctl age feh"

ALL="$TERMINAL $BROWSERS $EDITORS $VCS $TOOLS $MATH $PYTHON $RUST $NODE $TEX $X11 $MISC"
set -x
sudo pacman --needed -S $ALL
set +x
ask "Want to install pacman packages?"
if [ $? -eq 0 ]; then
set -x
sudo pacman --needed -S $ALL
set +x
fi

# TODO: Check if yay is already installed
ask "Want to install yay?"
Expand Down Expand Up @@ -113,6 +112,13 @@ fi
echo 'Done with OS-specific setup'
echo

ask "Want to install pipx packages?"
if [ $? -eq 0 ]; then
for package in $PIPX_PACKAGES; do
pipx install $package
done
fi

ask "Want to user-install Python packages?"
if [ $? -eq 0 ]; then
PYTHON_PACKAGES="numpy scipy pandas matplotlib powerline-status"
Expand Down

0 comments on commit a286815

Please sign in to comment.