From 0e75692511076967a81c6261f3b166d7e02c67b1 Mon Sep 17 00:00:00 2001 From: gzagatti Date: Tue, 27 Feb 2024 12:42:47 +0100 Subject: [PATCH] fix env variables (PATH, MANPATH), config zsh to allow editor line editing --- shells/bashrc | 25 +++++++++++++++++-------- shells/profile | 37 +++++++++++++++++++++++++++++++++++++ shells/zshrc | 32 ++++++++++++++++++++------------ 3 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 shells/profile diff --git a/shells/bashrc b/shells/bashrc index 67f59a8..1fc9da5 100644 --- a/shells/bashrc +++ b/shells/bashrc @@ -56,12 +56,14 @@ if [[ $- == *i* ]]; then ## }}} ## brew {{{ - if [ -f $HOME/.linuxbrew/bin/brew ]; then - export HOMEBREW_PREFIX=$HOME/.linuxbrew - elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then - export HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew - elif hash brew &>/dev/null && [[ -z "$HOMEBREW_PREFIX" ]]; then - export HOMEBREW_PREFIX=$(brew --prefix) + if [[ -z "$HOMEBREW_PREFIX" ]]; then + if [ -f $HOME/.linuxbrew/bin/brew ]; then + export HOMEBREW_PREFIX=$HOME/.linuxbrew + elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then + export HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew + elif hash brew &>/dev/null && [[ -z "$HOMEBREW_PREFIX" ]]; then + export HOMEBREW_PREFIX=$(brew --prefix) + fi fi if [[ -n "$HOMEBREW_PREFIX" ]]; then @@ -98,7 +100,7 @@ if [[ $- == *i* ]]; then ## rust {{{ if hash cargo 2>/dev/null; then - export PATH=$HOME/.cargo/bin${PATH+:$PATH} + export PATH=$HOME/.cargo/bin${PATH:+:$PATH} fi ## }}} @@ -117,6 +119,13 @@ if [[ $- == *i* ]]; then fi ## }}} + ## julia {{{ + if hash julia 2>/dev/null; then + # LD_LIBRARY_PATH set by nix conflicts with julia + alias julia='LD_LIBRARY_PATH= julia' + fi + ## }}} + ## go {{{ if hash go 2>/dev/null; then export GOPATH=$HOME/.go @@ -295,7 +304,7 @@ if [[ $- == *i* ]]; then # PATH {{{ # add ~/.local/bin to PATH to the front of the path export PATH=$HOME/.local/bin:$PATH - # removes duplicates from the PATH, given that the above can introduce duplicates + # removes duplicates from the PATH PATH=`printf %s "$PATH" | awk -v RS=: '{ if (!arr[$0]++) {printf("%s%s",!ln++?"":":",$0)}}'` # }}} diff --git a/shells/profile b/shells/profile new file mode 100644 index 0000000..c0a20e0 --- /dev/null +++ b/shells/profile @@ -0,0 +1,37 @@ +# ~/.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 + +# fix XDG_DATA_DIRS set by nix +if [ -f $HOME/.nix-profile/bin/home-manager ]; then + export XDG_DATA_DIRS=$(echo $XDG_DATA_DIRS | sed -e 's|/home/gzagatti/.nix-profile/share:||' -e 's|/nix/var/nix/profiles/default/share:||') + export XDG_DATA_DIRS="${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${HOME}/.nix-profile/share:/nix/var/nix/profiles/default/share" +fi + +# set brew env variables so it includes if brew is installed +if [ -f $HOME/.linuxbrew/bin/brew ]; then + export HOMEBREW_PREFIX=$HOME/.linuxbrew +elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then + export HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew +elif hash brew &>/dev/null && [[ -z "$HOMEBREW_PREFIX" ]]; then + export HOMEBREW_PREFIX=$(brew --prefix) +fi + +# add brew to XDG_DATA_DIRS +if [[ -n "$HOMEBREW_PREFIX" ]]; then + export PATH="$HOMEBREW_PREFIX/bin:$HOMEBREW_PREFIX/sbin${PATH+:$PATH}" + export XDG_DATA_DIRS="${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}$HOMEBREW_PREFIX/share/" +fi diff --git a/shells/zshrc b/shells/zshrc index e34cd7d..4c7060b 100644 --- a/shells/zshrc +++ b/shells/zshrc @@ -8,9 +8,12 @@ if [[ $- == *i* ]]; then # Shell options {{{ setopt NO_CASE_GLOB setopt AUTO_CD + autoload edit-command-line + zle -N edit-command-line bindkey -v bindkey "^?" backward-delete-char bindkey "^R" history-incremental-search-backward + bindkey -M vicmd v edit-command-line # }}} # History {{{ @@ -48,20 +51,19 @@ if [[ $- == *i* ]]; then ## }}} ## brew {{{ - if [ -f $HOME/.linuxbrew/bin/brew ]; then - export HOMEBREW_PREFIX=$HOME/.linuxbrew - elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then - export HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew - elif hash brew &>/dev/null && [[ -z "$HOMEBREW_PREFIX" ]]; then - export HOMEBREW_PREFIX=$(brew --prefix) + if [[ -z "$HOMEBREW_PREFIX" ]]; then + if [ -f $HOME/.linuxbrew/bin/brew ]; then + export HOMEBREW_PREFIX=$HOME/.linuxbrew + elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then + export HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew + elif hash brew &>/dev/null && [[ -z "$HOMEBREW_PREFIX" ]]; then + export HOMEBREW_PREFIX=$(brew --prefix) + fi fi if [[ -n "$HOMEBREW_PREFIX" ]]; then export HOMEBREW_CELLAR=$HOMEBREW_PREFIX/Cellar export HOMEBREW_REPOSITORY=$HOMEBREW_PREFIX/Homebrew - # ${parameter+alt_value} if parameter set use alt_value else use null string - export MANPATH="$HOMEBREW_PREFIX/share/man${MANPATH+:$MANPATH}:" - export INFOPATH="$HOMEBREW_PREFIX/share/info${INFOPATH+:$INFOPATH}" export PATH="$HOMEBREW_PREFIX/bin:$HOMEBREW_PREFIX/sbin${PATH+:$PATH}" export FPATH="$HOMEBREW_PREFIX/share/zsh/site-functions${FPATH+:$FPATH}" hash -f @@ -97,7 +99,7 @@ if [[ $- == *i* ]]; then ## rust {{{ if hash cargo 2>/dev/null; then - export PATH=$HOME/.cargo/bin${PATH+:$PATH} + export PATH=$HOME/.cargo/bin${PATH:+:$PATH} fi ## }}} @@ -116,6 +118,13 @@ if [[ $- == *i* ]]; then fi ## }}} + ## julia {{{ + if hash julia 2>/dev/null; then + # LD_LIBRARY_PATH set by nix conflicts with julia + alias julia='LD_LIBRARY_PATH= julia' + fi + ## }}} + ## go {{{ if hash go 2>/dev/null; then export GOPATH=$HOME/.go @@ -132,7 +141,6 @@ if [[ $- == *i* ]]; then fi ## }}} - ## kitty {{{ if test -n "$KITTY_INSTALLATION_DIR"; then export KITTY_SHELL_INTEGRATION="enabled" @@ -361,7 +369,7 @@ if [[ $- == *i* ]]; then # PATH {{{ # add ~/.local/bin to PATH to the front of the path export PATH=$HOME/.local/bin:$PATH - # removes duplicates from the PATH, given that the above can introduce duplicates + # removes duplicates from the PATH PATH=`printf %s "$PATH" | awk -v RS=: '{ if (!arr[$0]++) {printf("%s%s",!ln++?"":":",$0)}}'` # }}}