add bashrc.root
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
# i.e., add at the end of .bashrc:
|
||||
# [ -f "$HOME/.bashrc.$USER" ] && . "$HOME/.bashrc.$USER"
|
||||
#
|
||||
# Debian default ~/.profile does:
|
||||
# Debian default ~/.profile usually does:
|
||||
# 1) source .bashrc if it exists
|
||||
# 2) add "$HOME"/bin in PATH
|
||||
# This imply a duplicate "$HOME/bin" in PATH, as we do everything here.
|
||||
@@ -130,6 +130,8 @@ e() {
|
||||
$VISUAL "$@"
|
||||
}
|
||||
export -f e
|
||||
|
||||
# look for Emacs
|
||||
if hash emacs 2>/dev/null; then
|
||||
# uncomment below to use full emacs
|
||||
#export EDITOR=emacs
|
||||
@@ -189,7 +191,7 @@ export QUOTING_STYLE=literal
|
||||
# avoid these stupid systemd defaults (horizontal scroll and pager)
|
||||
alias systemctl="systemctl --no-pager --full"
|
||||
|
||||
# useful aliases/functions
|
||||
# aliases/functions for ls and history
|
||||
alias l='ls -F'
|
||||
alias ls='ls -F'
|
||||
alias l1='ls -1F'
|
||||
|
211
config/home/bashrc.root
Normal file
211
config/home/bashrc.root
Normal file
@@ -0,0 +1,211 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# ~/.bashrc.root - root bash startup
|
||||
#
|
||||
# (C) Bruno Raoult ("br"), 2001-2024
|
||||
# Licensed under the GNU General Public License v3.0 or later.
|
||||
# Some rights reserved. See COPYING.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with this
|
||||
# program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||
#
|
||||
# Usage: to be invoked from .bashrc.
|
||||
# i.e., add at the end of .bashrc:
|
||||
# [ -f "$HOME/.bashrc.$USER" ] && . "$HOME/.bashrc.$USER"
|
||||
#
|
||||
# Debian default ~/.profile usually does:
|
||||
# 1) source .bashrc if it exists
|
||||
# 2) add "$HOME"/bin in PATH
|
||||
# This imply a duplicate "$HOME/bin" in PATH, as we do everything here.
|
||||
# Better to have a ~/.bash_profile with the lines above.
|
||||
|
||||
# _var_del() - remove an element from a colon-separated list.
|
||||
# $1: name (reference) of a colon separated list
|
||||
# $2: element to remove (string)
|
||||
#
|
||||
# _var_del() removes every occurrence of $2, if there are more than 1,
|
||||
# and leaves $1 unchanged if $2 is not present.
|
||||
#
|
||||
# Example:
|
||||
# With VAR's value being "foo:bar:quax:bar". Using "_var_del VAR bar" will
|
||||
# leave VAR with the value "foo:quax".
|
||||
_var_del() {
|
||||
local -n _p_del=$1
|
||||
local _l=":$_p_del:"
|
||||
|
||||
while [[ $_l =~ :$2: ]]; do
|
||||
_l=${_l//:$2:/:}
|
||||
done
|
||||
_l=${_l%:}
|
||||
_l=${_l#:}
|
||||
_p_del="$_l"
|
||||
}
|
||||
|
||||
# _var_prepend() - prepend element to colon-separated variable.
|
||||
# $1: variable name (reference)
|
||||
# $2: element to add (string)
|
||||
#
|
||||
# Any occurrence of $2 in $1 is first removed, then $2 is added at $1 beginning.
|
||||
#
|
||||
# Example:
|
||||
# With VAR's value being "foo:bar:quax:bar". Using "_var_prepend VAR bar"
|
||||
# will leave VAR with the value "bar:foo:quax".
|
||||
_var_prepend() {
|
||||
local -n _p_prepend=$1
|
||||
|
||||
_var_del _p_prepend "$2"
|
||||
[[ -z $_p_prepend ]] && _p_prepend="$2" && return
|
||||
_p_prepend="$2:$_p_prepend"
|
||||
}
|
||||
|
||||
# _var_append() - append element to colon-separated variable.
|
||||
# $1: variable name (reference)
|
||||
# $2: element to add (string)
|
||||
#
|
||||
# Any occurrence of $2 in $1 is first removed, then $2 is added at $1 end.
|
||||
#
|
||||
# Example:
|
||||
# With VAR's value being "foo:bar:quax:bar". Using "_var_append VAR bar"
|
||||
# will leave VAR with the value "foo:quax:bar".
|
||||
_var_append() {
|
||||
local -n _p_append=$1
|
||||
|
||||
_var_del _p_append "$2"
|
||||
[[ -z $_p_append ]] && _p_append="$2" && return
|
||||
_p_append="$_p_append:$2"
|
||||
}
|
||||
|
||||
# adjust PATH. Below paths will be added at beginning.
|
||||
_lpath=("$HOME/bin/$(uname -s)-$(uname -m)"
|
||||
"$HOME/bin"
|
||||
"/usr/local/bin")
|
||||
|
||||
# loop array in reverse order. Note: We do not test for path existence and add it
|
||||
# unconditionally, to avoid automounter interference.
|
||||
for (( _i = ${#_lpath[@]} - 1; _i >= 0; --_i )); do
|
||||
_var_prepend PATH "${_lpath[_i]}"
|
||||
done
|
||||
unset _lpath
|
||||
|
||||
# enable core file
|
||||
ulimit -HSc 102400 # in 1024 bytes - Really cannot use KiB :-)
|
||||
|
||||
# ... and set PAGER to less (for man(1) and others)
|
||||
if hash less 2>/dev/null; then
|
||||
export PAGER=less
|
||||
# do not clear screen after "less", exit immediately if one page only
|
||||
export LESS="-XFB"
|
||||
# ... and just alias more... to less ;-)
|
||||
alias more=less
|
||||
fi
|
||||
|
||||
# no output split for dc and bc / make bc silent
|
||||
export DC_LINE_LENGTH=0
|
||||
export BC_LINE_LENGTH=0
|
||||
export BC_ENV_ARGS=--quiet
|
||||
|
||||
# both ubuntu and debian assume we want colors if TERM contains "color"
|
||||
# this is surely not true, as TERM is often forced by terminal emulator
|
||||
# shellcheck disable=SC2154
|
||||
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*)
|
||||
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
# trim prompt path
|
||||
export PROMPT_DIRTRIM=3
|
||||
|
||||
# find a suitable editor
|
||||
e() {
|
||||
$VISUAL "$@"
|
||||
}
|
||||
export -f e
|
||||
|
||||
# no Emacs for root
|
||||
# emacs clones, then vim/vi, then... whatever left.
|
||||
_VISUALS=(zile mg jed vim vi nano ed)
|
||||
for e in "${_VISUALS[@]}"; do
|
||||
if hash "$e" 2>/dev/null; then
|
||||
export VISUAL="$e"
|
||||
break
|
||||
fi
|
||||
done
|
||||
unset _VISUALS
|
||||
export EDITOR=$VISUAL
|
||||
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
# write history after each command
|
||||
export PROMPT_COMMAND="history -a"
|
||||
# Add timestamp in history
|
||||
export HISTTIMEFORMAT="%d/%m %H:%M "
|
||||
# ignore history dups, delete all previous dups
|
||||
export HISTCONTROL="ignorespace:ignoredups:erasedups"
|
||||
# ignore these in history
|
||||
export HISTIGNORE="history *:h:hl:hll:hlll"
|
||||
# history size
|
||||
HISTSIZE=5000
|
||||
HISTFILESIZE=5000
|
||||
|
||||
# remove new stupid Debian "ls" quoting, and colors...
|
||||
# Many complains, one of them:
|
||||
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=813164#226
|
||||
export QUOTING_STYLE=literal
|
||||
[[ -v BASH_ALIASES[ls] ]] && unalias ls
|
||||
|
||||
# aliases/functions for ls and history
|
||||
alias l='ls -F'
|
||||
alias ls='ls -F'
|
||||
alias l1='ls -1F'
|
||||
alias la='ls -AF'
|
||||
alias ll='ls -lF'
|
||||
alias lla='ls -lAF'
|
||||
alias ldl='ls -l | grep ^d'
|
||||
[[ -v BASH_ALIASES[lrt] ]] && unalias lrt
|
||||
lrt() {
|
||||
local -i _l=20
|
||||
if (( $# > 0 )) && [[ $1 =~ [[:digit:]]+ ]]; then
|
||||
_l="$1"
|
||||
shift
|
||||
fi
|
||||
# shellcheck disable=2012
|
||||
ls -lrt "${1:-.}" | tail -"$_l"
|
||||
}
|
||||
[[ -v BASH_ALIASES[lart] ]] && unalias lart
|
||||
lart() {
|
||||
local -i _l=20
|
||||
if (( $# > 0 )) && [[ $1 =~ [[:digit:]]+ ]]; then
|
||||
_l="$1"
|
||||
shift
|
||||
fi
|
||||
# shellcheck disable=2012
|
||||
ls -laFrt "${1:-.}" | tail -"$_l"
|
||||
}
|
||||
|
||||
alias h="history 10" # short
|
||||
alias hl="history 25" # long
|
||||
alias hll="history 100" # very long
|
||||
alias hlll="history" # all history
|
||||
|
||||
alias grep='grep --color=auto' # add colors to grep
|
||||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
|
||||
# misc aliases
|
||||
alias fuck='sudo $(history -p \!\!)'
|
||||
alias diff='diff -u'
|
||||
|
||||
# Indent style for emacs
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-basic-offset: 4
|
||||
# sh-indentation: 4
|
||||
# indent-tabs-mode: nil
|
||||
# comment-column: 32
|
||||
# End:
|
Reference in New Issue
Block a user