Created
July 5, 2022 02:21
-
-
Save longtc/3d84c50146540bce4d30b89e19648e40 to your computer and use it in GitHub Desktop.
bash shell config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### ea - alias for editing aliases | |
# | |
#When setting up a new aliases file, or having creating a new file.. About every time after editing an aliases file, I source it. This alias makes editing alias a | |
#bit easier and they are useful right away. Note if the source failed, it will not echo "aliases sourced". | |
# | |
#Sub in gedit for your favorite editor, or alter for ksh, sh, etc. | |
# | |
alias ea='nano ~/.bash_aliases; source ~/.bash_aliases && source $HOME/.bash_aliases && echo "aliases sourced --ok."' | |
# | |
##### Useful shell option ##### | |
# Entering a directory name as a bare word will change into that directory | |
shopt -s autocd | |
# Automatically correct off-by-one typing mistakes when changing directories | |
shopt -s cdspell | |
# Make Bash wrap text properly if the terminal size changes | |
shopt -s checkwinsize | |
# Store multi-line commands in shell history as one-liners for easy editing | |
shopt -s cmdhist | |
# Correct off-by-one typing mistakes when tab-completing directories | |
shopt -s dirspell | |
# Allow aliases to be expanded even in non-interactive sessions | |
shopt -s expand_aliases | |
# Enable fancy globbing functions | |
shopt -s extglob | |
# Enable the recursive glob (**) function | |
shopt -s globstar | |
# Don't clobber other sessions' changes to global history when exiting | |
shopt -s histappend | |
# Don't try to complete on empty lines | |
shopt -s no_empty_cmd_completion | |
# Globs won't consider case | |
shopt -s nocaseglob | |
# Globs will consider hidden files, too | |
shopt -s dotglob | |
#Stop bash from caching duplicate lines. | |
HISTCONTROL=ignoredups | |
##### Color definitions ##### | |
### Control ### | |
export color_N=$(tput sgr0) # Normal | |
export color_F=$(tput blink) # Blink | |
### Standard ### | |
export color_L=$(tput sgr0; tput setaf 0) # Black | |
export color_R=$(tput sgr0; tput setaf 1) # Red | |
export color_G=$(tput sgr0; tput setaf 2) # Green | |
export color_Y=$(tput sgr0; tput setaf 3) # Yellow | |
export color_B=$(tput sgr0; tput setaf 4) # Blue | |
export color_P=$(tput sgr0; tput setaf 5) # Magenta | |
export color_C=$(tput sgr0; tput setaf 6) # Cyan | |
export color_W=$(tput sgr0; tput setaf 7) # White | |
### Intense ### | |
export color_l=$(tput bold ; tput setaf 0) # Black | |
export color_r=$(tput bold ; tput setaf 1) # Red | |
export color_g=$(tput bold ; tput setaf 2) # Green | |
export color_y=$(tput bold ; tput setaf 3) # Yellow | |
export color_b=$(tput bold ; tput setaf 4) # Blue | |
export color_p=$(tput bold ; tput setaf 5) # Magenta | |
export color_c=$(tput bold ; tput setaf 6) # Cyan | |
export color_w=$(tput bold ; tput setaf 7) # White | |
### Background ### | |
export color_LB=$(tput sgr0; tput setab 0) # Black | |
export color_RB=$(tput sgr0; tput setab 1) # Red | |
export color_GB=$(tput sgr0; tput setab 2) # Green | |
export color_YB=$(tput sgr0; tput setab 3) # Yellow | |
export color_BB=$(tput sgr0; tput setab 4) # Blue | |
export color_PB=$(tput sgr0; tput setab 5) # Magena | |
export color_CB=$(tput sgr0; tput setab 6) # Cyan | |
export color_WB=$(tput sgr0; tput setab 7) # White | |
##### Set terminal title ##### | |
title () { | |
[[ "${TERM}" != 'linux' ]] && | |
printf "\033]0;%s\007\n" "$@" | |
} | |
##### Generate prompt color scheme based on host- and username ##### | |
color_Tn () { | |
n=$((0x$(echo $HOSTNAME | md5sum | cut -d' ' -f1))) | |
echo $((${n/-/} + UID)) | |
} | |
color_Sn () { | |
n=$((0x$(echo ${USER}${HOSTNAME} | md5sum | cut -d' ' -f1))) | |
echo $((${n/-/})) | |
} | |
colors_T=(R G Y B P C) | |
colors_S=(R G Y B P C N) | |
color_T="color_${colors_T[$(($(color_Tn) % ${#colors_T[@]}))]}" | |
color_t=$(echo $color_T | tr '[:upper:]' '[:lower:]') | |
color_S="color_${colors_S[$(($(color_Sn) % ${#colors_S[@]}))]}" | |
color_s=$(echo $color_S | tr '[:upper:]' '[:lower:]') | |
unset colors_T | |
unset colors_S | |
unset color_Tn | |
unset color_Sn | |
export color_T=${!color_T} | |
export color_t=${!color_t} | |
export color_S=${!color_S} | |
export color_s=${!color_s} | |
prompt_function () { | |
title "$HOSTNAME" | |
} | |
export PROMPT_COMMAND='prompt_function' | |
if ((UID != 0)); then | |
export PS1="\[$color_S\]\h\[$color_N\]:\[$color_t\]\w\[$color_T\]\\$\[$color_N\] " | |
else | |
export PS1="\[$color_s\]\h\[$color_t\]:\[$color_s\]\w\[$color_S\]\\$\[$color_N\] " | |
fi | |
##### Aliases ##### | |
# Bashmarks | |
source ~/.local/bin/bashmarks.sh | |
alias l='ls -alF' | |
alias p8='ping 8.8.8.8' | |
# Lazily search for files in multiple paths | |
f() { | |
q="$1" | |
shift | |
if [ "$#" = "0" ]; then | |
set "." | |
fi | |
for dir in "$@"; do | |
find "$dir" -iname "*$q*" | |
shift | |
done | |
} | |
# Lazily change into directories using only partial names | |
c () { | |
ls='ls -A -sh --color=auto' | |
if [[ $1 ]]; then | |
if [[ $1 == '-q' ]]; then | |
ls='true' | |
shift | |
fi | |
for dir in "$@"; do | |
if [[ -d $dir ]]; then | |
command cd "$dir" | |
else | |
command cd *"${dir}"* | |
fi | |
done | |
else | |
command cd ~ | |
fi | |
$ls | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.bashrc: executed by bash(1) for non-login shells. | |
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return;; | |
esac | |
# don't put duplicate lines or lines starting with space in the history. | |
# See bash(1) for more options | |
HISTCONTROL=ignoreboth | |
# append to the history file, don't overwrite it | |
shopt -s histappend | |
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) | |
HISTSIZE=1000 | |
HISTFILESIZE=2000 | |
# check the window size after each command and, if necessary, | |
# update the values of LINES and COLUMNS. | |
shopt -s checkwinsize | |
# If set, the pattern "**" used in a pathname expansion context will | |
# match all files and zero or more directories and subdirectories. | |
#shopt -s globstar | |
# make less more friendly for non-text input files, see lesspipe(1) | |
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
# set variable identifying the chroot you work in (used in the prompt below) | |
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then | |
debian_chroot=$(cat /etc/debian_chroot) | |
fi | |
# set a fancy prompt (non-color, unless we know we "want" color) | |
case "$TERM" in | |
xterm-color|*-256color) color_prompt=yes;; | |
esac | |
# uncomment for a colored prompt, if the terminal has the capability; turned | |
# off by default to not distract the user: the focus in a terminal window | |
# should be on the output of commands, not on the prompt | |
#force_color_prompt=yes | |
if [ -n "$force_color_prompt" ]; then | |
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
# We have color support; assume it's compliant with Ecma-48 | |
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
# a case would tend to support setf rather than setaf.) | |
color_prompt=yes | |
else | |
color_prompt= | |
fi | |
fi | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
fi | |
unset color_prompt force_color_prompt | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm*|rxvt*) | |
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" | |
;; | |
*) | |
;; | |
esac | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=auto' | |
#alias dir='dir --color=auto' | |
#alias vdir='vdir --color=auto' | |
#alias grep='grep --color=auto' | |
#alias fgrep='fgrep --color=auto' | |
#alias egrep='egrep --color=auto' | |
fi | |
# colored GCC warnings and errors | |
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' | |
# some more ls aliases | |
#alias ll='ls -l' | |
#alias la='ls -A' | |
#alias l='ls -CF' | |
# Alias definitions. | |
# You may want to put all your additions into a separate file like | |
# ~/.bash_aliases, instead of adding them here directly. | |
# See /usr/share/doc/bash-doc/examples in the bash-doc package. | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
# enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment