Compare commits

...

19 Commits

Author SHA1 Message Date
63b2ea7388 Use which instead of type so that bash doesnt report error to GUI 2025-05-06 22:47:43 +08:00
bd9bc865ab Add alias for winget if present 2025-04-29 17:07:19 +08:00
1a943907db Fix spacing when error is shown 2025-04-29 15:56:50 +08:00
e903a3a256 Add return value to bash prompt 2025-04-29 15:54:59 +08:00
1c69b6de79 Add return value to zsh prompt if nonzero 2025-04-29 14:11:07 +08:00
f203391ee6 Add profile-post files for variables that need to be initialized last 2025-04-18 18:04:53 +08:00
2a71415f0f Fix comment color position 2025-04-16 22:05:35 +08:00
2a6cc1709a Change comment color scheme in for readability in macos 2025-04-16 22:02:21 +08:00
954ee8eadb Add iterm2 integration for macos 2025-04-14 14:27:25 +08:00
935da20ddf Add HIST_IGNORE_SPACE 2024-06-16 18:18:11 +08:00
a1e8f2f9f9 Cleanup perl includes (rarely used) 2024-03-30 14:39:07 +08:00
ddec4491fd Change apt to dnf 2024-03-29 13:06:27 +08:00
e5c1bba6a6 Use raw install.sh instead of src 2024-03-29 13:04:54 +08:00
ab660d570d Update formatting 2024-03-23 13:26:53 +08:00
a583e27d69 Add description of profile repo 2024-03-23 13:24:29 +08:00
cc4eb4f544 Add support for RHEL / Oracle (9xx) 2024-03-23 13:13:29 +08:00
0a659528a4 Make sure to emulate /etc/profile in bash 2024-03-23 12:59:04 +08:00
49b97d5697 Update pyenv - no more need for workarounds 2024-03-23 12:58:34 +08:00
0ba21d0238 Update remote url to gitea 2024-03-23 12:57:12 +08:00
9 changed files with 344 additions and 16 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
backup/ backup/
skel/.profile-local skel/.profile-local
skel/.profile-private skel/.profile-private
skel/.profile-post-local
skel/.profile-post-private

View File

@@ -1,10 +1,35 @@
Git repo of my personal shell profile variables ## What this is
This is a Git repo of my personal shell profile and preferred working environment. You are free to use it if you think / work like me.
## What does this do?
- works with the package manager to install my preferred tools
- use zsh by default
- enables oh-my-zsh with gentoo colors and the following plugins / settings
- git
- per-directory-history
- zsh-autosuggestions
- zsh-syntax-highlighting
- interactive comments
- `RM_STAR_WAIT` - wait 10 seconds before agreeing to `rm *`
- effectively unlimited history
- use phpenv, rbenv, pyenv, etc if installed
- vim as default editor with the following plugins / settings
- vim-fugitive
- vim-sleuth
- Vundle
- ignorecase / smartcase search
- `_` character counted as iskeyword
- all of the above with automation conveniences
- installer script, so i can run on any new PC / VM
- backs up current configs
- allows you to set local configs tracked separately from git
## Installing ## Installing
### Quick Install ### Quick Install
``` ```
curl https://gitlab.com/madumlao/madumlao-profile/-/raw/master/install.sh | bash curl https://gitea.madumlao.com/madumlao/madumlao-profile/raw/branch/master/install.sh | bash
``` ```
### Manual Install ### Manual Install

80
install-rhel.sh Executable file
View File

@@ -0,0 +1,80 @@
#!/bin/bash
# run by install.sh
# tested on os-release 9,3
APP_DIR="$(dirname "$0")"
echo "Run a dnf update"
if sudo -l dnf > /dev/null; then
sudo dnf check-update
else
echo "Unable to run dnf commands, please install manually"
fi
echo "Install git and friends"
if sudo -l dnf > /dev/null; then
sudo dnf install -y git
else
echo "Unable to autoinstall git and friends, please install manually"
fi
echo "Install zsh and friends"
if sudo -l dnf > /dev/null; then
sudo dnf install -y zsh PackageKit-command-not-found sqlite
else
echo "Unable to autoinstall zsh and friends, please install manually"
fi
echo "Install oh-my-zsh and plugins"
if ! [ -d "$HOME/.oh-my-zsh" ]; then
git clone https://github.com/ohmyzsh/ohmyzsh "$HOME/.oh-my-zsh"
fi
(
cd "$HOME/.oh-my-zsh/plugins"
git clone https://github.com/zsh-users/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting
)
echo "Changing default shell"
ZSH_PATH="$(which zsh)"
if [ -x "$ZSH_PATH" ]; then
if sudo -l chsh -s $ZSH_PATH $USER; then
sudo chsh -s $ZSH_PATH $USER
elif sudo -l usermod -s $ZSH_PATH $USER; then
sudo usermod -s $ZSH_PATH $USER
else
echo "Cannot change shell using sudo, trying password"
if ! chsh -s "$ZSH_PATH"; then
echo "Unable to change shell to $ZSH_PATH, please change shell manually"
fi
fi
else
echo "No zsh available"
fi
SKEL_DIR="$APP_DIR/skel"
BACK_DIR="$APP_DIR/backup"
echo "Backing up original profile under $BACK_DIR"
mkdir -pv "$BACK_DIR"
cd "$SKEL_DIR"
OLDIFS="$IFS"
IFS=$'\n'
for x in $(ls -a); do
[ "$x" = '.' ] || [ "$x" = '..' ] && continue;
[ "$x" = '.profile-local' ] || [ "$x" = '.profile-private' ] && continue;
[ -r "$HOME/$x" ] && echo -ne "Backup: " && mv -v "$HOME/$x" "$BACK_DIR"
echo -ne "Linking: " && ln -srv "$(pwd)/$x" "$HOME"
done
IFS="$OLDIFS"
echo "Install vim and friends"
if sudo -l dnf > /dev/null; then
sudo dnf install -y vim-enhanced
else
echo "Unable to autoinstall vim and friends, please install manually"
fi
mkdir -pv "$HOME/.vim/bundle"
git clone https://github.com/VundleVim/Vundle.vim "$HOME/.vim/bundle/Vundle.vim"
vim +PluginInstall +qall

View File

@@ -14,9 +14,9 @@ if [ "$DOWNLOAD_APP" ]; then
mkdir -pv "$PARENT_DIR" mkdir -pv "$PARENT_DIR"
if [ -x git ]; then if [ -x git ]; then
cd "$PARENT_DIR" cd "$PARENT_DIR"
git clone https://gitlab.com/madumlao/madumlao-profile git clone https://gitea.madumlao.com/madumlao/madumlao-profile
else else
curl -O https://gitlab.com/madumlao/madumlao-profile/-/archive/master/madumlao-profile-master.tar.gz curl -o madumlao-profile-master.tar.gz https://gitea.madumlao.com/madumlao/madumlao-profile/archive/master.tar.gz
tar -zxf madumlao-profile-master.tar.gz -C "$PARENT_DIR" tar -zxf madumlao-profile-master.tar.gz -C "$PARENT_DIR"
fi fi
fi fi
@@ -26,8 +26,21 @@ cd "$APP_DIR"
APP_DIR="$(pwd)" APP_DIR="$(pwd)"
if [ "$(uname)" == "Linux" ]; then if [ "$(uname)" == "Linux" ]; then
# TODO: add support for different distributions # detect WSL
./install-ubuntu.sh if uname -r | grep -q WSL > /dev/null; then
export PROFILE_WSL=y
fi
source /etc/os-release
export PROFILE_DISTRO="$ID"
export PROFILE_DISTRO_VERSION="$VERSION_ID"
export PROFILE_DISTRO_CODENAME="$VERSION_CODENAME"
export PROFILE_DISTRO_FAMILY="$ID_LIKE"
case "$PROFILE_DISTRO" in
ubuntu ) ./install-ubuntu.sh ;;
ol | rhel ) ./install-rhel.sh ;;
* ) echo "Unknown distro, install manually"
esac
elif [ "$(uname)" == "Darwin" ]; then elif [ "$(uname)" == "Darwin" ]; then
echo TODO: install-macos.sh echo TODO: install-macos.sh
else else

View File

@@ -34,7 +34,7 @@ shopt -s checkwinsize
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot) debian_chroot=$(cat /etc/debian_chroot)
fi fi
$()
# set a fancy prompt (non-color, unless we know we "want" color) # set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in case "$TERM" in
xterm*) color_prompt=yes;; xterm*) color_prompt=yes;;
@@ -72,6 +72,15 @@ xterm*|rxvt*)
;; ;;
esac esac
# Add goodies to PS1
export BASE_PS1="$PS1"
export BASE_PS1="$(echo "$BASE_PS1" | sed 's!\\\$ $!!g')"
export BASE_PS1_END=' \$ '
# show return value if prompt is nonzero
export BASH_GOODIES_RETURNVAL='$([ "$?" = 0 ] && echo "" || echo " \e[31m\][$?]\[\e[0m\]")'
PS1="${BASE_PS1}${BASH_GOODIES_RETURNVAL}${BASE_PS1_END}"
# enable color support of ls and also add handy aliases # enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"

View File

@@ -0,0 +1,178 @@
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
if [[ -o interactive ]]; then
if [ "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "tmux-256color" -a "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "screen" -a "${ITERM_SHELL_INTEGRATION_INSTALLED-}" = "" -a "$TERM" != linux -a "$TERM" != dumb ]; then
ITERM_SHELL_INTEGRATION_INSTALLED=Yes
ITERM2_SHOULD_DECORATE_PROMPT="1"
# Indicates start of command output. Runs just before command executes.
iterm2_before_cmd_executes() {
if [ "$TERM_PROGRAM" = "iTerm.app" ]; then
printf "\033]133;C;\r\007"
else
printf "\033]133;C;\007"
fi
}
iterm2_set_user_var() {
printf "\033]1337;SetUserVar=%s=%s\007" "$1" $(printf "%s" "$2" | base64 | tr -d '\n')
}
# Users can write their own version of this method. It should call
# iterm2_set_user_var but not produce any other output.
# e.g., iterm2_set_user_var currentDirectory $PWD
# Accessible in iTerm2 (in a badge now, elsewhere in the future) as
# \(user.currentDirectory).
whence -v iterm2_print_user_vars > /dev/null 2>&1
if [ $? -ne 0 ]; then
iterm2_print_user_vars() {
true
}
fi
iterm2_print_state_data() {
local _iterm2_hostname="${iterm2_hostname-}"
if [ -z "${iterm2_hostname:-}" ]; then
_iterm2_hostname=$(hostname -f 2>/dev/null)
fi
printf "\033]1337;RemoteHost=%s@%s\007" "$USER" "${_iterm2_hostname-}"
printf "\033]1337;CurrentDir=%s\007" "$PWD"
iterm2_print_user_vars
}
# Report return code of command; runs after command finishes but before prompt
iterm2_after_cmd_executes() {
printf "\033]133;D;%s\007" "$STATUS"
iterm2_print_state_data
}
# Mark start of prompt
iterm2_prompt_mark() {
printf "\033]133;A\007"
}
# Mark end of prompt
iterm2_prompt_end() {
printf "\033]133;B\007"
}
# There are three possible paths in life.
#
# 1) A command is entered at the prompt and you press return.
# The following steps happen:
# * iterm2_preexec is invoked
# * PS1 is set to ITERM2_PRECMD_PS1
# * ITERM2_SHOULD_DECORATE_PROMPT is set to 1
# * The command executes (possibly reading or modifying PS1)
# * iterm2_precmd is invoked
# * ITERM2_PRECMD_PS1 is set to PS1 (as modified by command execution)
# * PS1 gets our escape sequences added to it
# * zsh displays your prompt
# * You start entering a command
#
# 2) You press ^C while entering a command at the prompt.
# The following steps happen:
# * (iterm2_preexec is NOT invoked)
# * iterm2_precmd is invoked
# * iterm2_before_cmd_executes is called since we detected that iterm2_preexec was not run
# * (ITERM2_PRECMD_PS1 and PS1 are not messed with, since PS1 already has our escape
# sequences and ITERM2_PRECMD_PS1 already has PS1's original value)
# * zsh displays your prompt
# * You start entering a command
#
# 3) A new shell is born.
# * PS1 has some initial value, either zsh's default or a value set before this script is sourced.
# * iterm2_precmd is invoked
# * ITERM2_SHOULD_DECORATE_PROMPT is initialized to 1
# * ITERM2_PRECMD_PS1 is set to the initial value of PS1
# * PS1 gets our escape sequences added to it
# * Your prompt is shown and you may begin entering a command.
#
# Invariants:
# * ITERM2_SHOULD_DECORATE_PROMPT is 1 during and just after command execution, and "" while the prompt is
# shown and until you enter a command and press return.
# * PS1 does not have our escape sequences during command execution
# * After the command executes but before a new one begins, PS1 has escape sequences and
# ITERM2_PRECMD_PS1 has PS1's original value.
iterm2_decorate_prompt() {
# This should be a raw PS1 without iTerm2's stuff. It could be changed during command
# execution.
ITERM2_PRECMD_PS1="$PS1"
ITERM2_SHOULD_DECORATE_PROMPT=""
# Add our escape sequences just before the prompt is shown.
# Use ITERM2_SQUELCH_MARK for people who can't modify PS1 directly, like powerlevel9k users.
# This is gross but I had a heck of a time writing a correct if statetment for zsh 5.0.2.
local PREFIX=""
if [[ $PS1 == *"$(iterm2_prompt_mark)"* ]]; then
PREFIX=""
elif [[ "${ITERM2_SQUELCH_MARK-}" != "" ]]; then
PREFIX=""
else
PREFIX="%{$(iterm2_prompt_mark)%}"
fi
PS1="$PREFIX$PS1%{$(iterm2_prompt_end)%}"
ITERM2_DECORATED_PS1="$PS1"
}
iterm2_precmd() {
local STATUS="$?"
if [ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]; then
# You pressed ^C while entering a command (iterm2_preexec did not run)
iterm2_before_cmd_executes
if [ "$PS1" != "${ITERM2_DECORATED_PS1-}" ]; then
# PS1 changed, perhaps in another precmd. See issue 9938.
ITERM2_SHOULD_DECORATE_PROMPT="1"
fi
fi
iterm2_after_cmd_executes "$STATUS"
if [ -n "$ITERM2_SHOULD_DECORATE_PROMPT" ]; then
iterm2_decorate_prompt
fi
}
# This is not run if you press ^C while entering a command.
iterm2_preexec() {
# Set PS1 back to its raw value prior to executing the command.
PS1="$ITERM2_PRECMD_PS1"
ITERM2_SHOULD_DECORATE_PROMPT="1"
iterm2_before_cmd_executes
}
# If hostname -f is slow on your system set iterm2_hostname prior to
# sourcing this script. We know it is fast on macOS so we don't cache
# it. That lets us handle the hostname changing like when you attach
# to a VPN.
if [ -z "${iterm2_hostname-}" ]; then
if [ "$(uname)" != "Darwin" ]; then
iterm2_hostname=`hostname -f 2>/dev/null`
# Some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option.
if [ $? -ne 0 ]; then
iterm2_hostname=`hostname`
fi
fi
fi
[[ -z ${precmd_functions-} ]] && precmd_functions=()
precmd_functions=($precmd_functions iterm2_precmd)
[[ -z ${preexec_functions-} ]] && preexec_functions=()
preexec_functions=($preexec_functions iterm2_preexec)
iterm2_print_state_data
printf "\033]1337;ShellIntegrationVersion=14;shell=zsh\007"
fi
fi

View File

@@ -89,19 +89,22 @@ PYENV_ROOT="${PYENV_ROOT:-${HOME}/.pyenv}"
if [ -z "$PYENV_DISABLE" ] && [ -d "$PYENV_ROOT/bin" ]; then if [ -z "$PYENV_DISABLE" ] && [ -d "$PYENV_ROOT/bin" ]; then
export PATH="$HOME/.pyenv/bin:$PATH" export PATH="$HOME/.pyenv/bin:$PATH"
export PIPENV_VENV_IN_PROJECT=1 export PIPENV_VENV_IN_PROJECT=1
PYENV_MAJOR_VERSION="$(pyenv --version|cut -f 2 -d ' '|cut -f 1 -d .)"
if [ "$PYENV_MAJOR_VERSION" -gt 1 ]; then
eval "$(pyenv init --path)"
fi
eval "$(pyenv init -)" eval "$(pyenv init -)"
fi fi
# perl # perl
export PATH="/home/madumlao/perl5/bin${PATH:+:${PATH}}"; export PATH; export PATH="$HOME/perl5/bin${PATH:+:${PATH}}"
export PERL5LIB="/home/madumlao/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB; export PERL5LIB="$HOME/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"
export PERL_LOCAL_LIB_ROOT="/home/madumlao/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT; export PERL_LOCAL_LIB_ROOT="$HOME/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"
export PERL_MB_OPT="--install_base \"/home/madumlao/perl5\""; export PERL_MB_OPT; export PERL_MB_OPT="--install_base \"$HOME/perl5\""
export PERL_MM_OPT="INSTALL_BASE=/home/madumlao/perl5"; export PERL_MM_OPT; export PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"
# aliases # aliases
alias less='less -i -r' alias less='less -i -r'
if which winget.exe >/dev/null 2>&1; then
alias winget="$(which winget.exe)"
fi
# profile variables that need to be defined late
[ -f "$HOME/.profile-post-local" ] && source "$HOME/.profile-post-local"
[ -f "$HOME/.profile-post-private" ] && source "$HOME/.profile-post-private"

View File

@@ -1,7 +1,18 @@
emulate bash
source /etc/profile source /etc/profile
emulate zsh
source $HOME/.profile source $HOME/.profile
# source kubernetes shell completion # source kubernetes shell completion
if whence kubectl > /dev/null && [ "$PROFILE_ENABLE_KUBECTL" ]; then if whence kubectl > /dev/null && [ "$PROFILE_ENABLE_KUBECTL" ]; then
source <(kubectl completion zsh) source <(kubectl completion zsh)
fi fi
# MacOS specific
if [ "$(uname)" = "Darwin" ]; then
if [ -f .iterm2_shell_integration ]; then
source .iterm2_shell_integration
fi
fi

View File

@@ -50,6 +50,9 @@ plugins=(git per-directory-history zsh-autosuggestions zsh-syntax-highlighting)
# User configuration # User configuration
source $ZSH/oh-my-zsh.sh source $ZSH/oh-my-zsh.sh
# setup colors
ZSH_HIGHLIGHT_STYLES[comment]=fg=cyan,bold
# interactive comments # interactive comments
setopt interactivecomments setopt interactivecomments
@@ -71,6 +74,7 @@ SAVEHIST=$HISTSIZE
setopt BANG_HIST # Treat the '!' character specially during expansion. setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt HIST_BEEP # Beep when accessing nonexistent history. setopt HIST_BEEP # Beep when accessing nonexistent history.
setopt HIST_LEX_WORDS # parse quotes when parsing history setopt HIST_LEX_WORDS # parse quotes when parsing history
setopt HIST_IGNORE_SPACE # dont save commands starting with space
# set GPG_TTY # set GPG_TTY
if [ "$GPG_TTY" = "" ]; then if [ "$GPG_TTY" = "" ]; then
@@ -82,3 +86,6 @@ emulate bash
[ -f "$HOME/.rc-local" ] && source "$HOME/.rc-local" [ -f "$HOME/.rc-local" ] && source "$HOME/.rc-local"
emulate zsh emulate zsh
[ -f "$HOME/.zshrc-local" ] && source "$HOME/.zshrc-local" [ -f "$HOME/.zshrc-local" ] && source "$HOME/.zshrc-local"
# Add return value to prompt if nonzero
PS1='%(!.%B%F{red}.%B%F{green}%n@)%m %F{blue}%(!.%1~.%~) ${vcs_info_msg_0_}%F{blue}%(?..%F{red}[%?] )%F{blue}%(!.#.$)%b%f '