Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Share Your BASH Aliases

Here you can discuss every aspect of Debian. Note: not for support requests!
Post Reply
Message
Author
User avatar
craigevil
Posts: 5391
Joined: 2006-09-17 03:17
Location: heaven
Has thanked: 28 times
Been thanked: 39 times

Share Your BASH Aliases

#1 Post by craigevil »

My ever growing bash_aliases:

Code: Select all

# Start gomuks Matrix Client
alias gomuks=/home/pi/Downloads/gomuks-linux-arm64

# Show open ports
alias ports='sudo netstat -tulanp'

# Refresh .bashrc
alias bashrc="source ~/.bashrc"

# become root #
alias root='sudo -i'
alias su='sudo -i'

# Fix which
alias which='command -v'

# APT User Commands
alias search='nala search'
alias file='apt-file search'
alias policy='apt policy'
alias show="nala show"
# if user is not root, pass all commands via sudo #
if [ $UID -ne 0 ]; then
alias update='sudo nala update -d'
alias ainstall='sudo apt install'
alias apurge='sudo apt purge -y --autoremove'
alias upgrade='sudo nala upgrade -y'
alias aremove='sudo apt autoremove -y'
alias clean='sudo nala clean'
alias reboot='sudo reboot'
alias shutdown="sudo shutdown -P now"
fi

# Handy-dandy aliases for journalctl and systemctl
alias jc='sudo journalctl -b'
alias jca='sudo journalctl'
alias jcf='sudo journalctl -f'
alias jcr='sudo journalctl --list-boots'
alias sc='sudo systemctl'

# Making files immortal & executable
alias im+="sudo chattr +i"
alias im-="sudo chattr -i"
alias exe="sudo chmod +x"

#Add safety nets
# do not delete / or prompt if deleting more than 3 files at a time #
alias rm='rm -I --preserve-root'
# confirmation #
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
# Parenting changing perms on / #
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'

# copy the current working directory to the clipboard
alias cpwd='pwd | xclip -selection clipboard'

# quick directory movement
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'

# go to the last directory you were in
alias back='cd $OLDPWD'

# quickly find files and directory
alias ff='find . -type f -name'
alias fd='find . -type d -name'

# Create Python virtual environment
alias ve='python3 -m venv ./venv'
alias va='source ./venv/bin/activate'

# Ping Commands
# Stop after sending count ECHO_REQUEST packets #
alias ping='ping -c 5'
alias pg="ping google.com -c 5"

# alias shortcuts
alias rpi="sudo rpi-update"
alias raspi="sudo raspi-config"
alias clr="clear"
alias clrh="history -c -w ~/.bash_history"
alias df='df -H'
alias du='du -ch'
alias mk="mkdir -p"
alias loading="sudo dmesg > ~/dmesg.txt"

# ls Commands
## Colorize the ls output and human readable sizes ##
alias ls='ls --color=auto --human-readable -al'
## Use a long listing format ##
alias ll='ls -la'
## Show hidden files ##
alias l.='ls -d .* --color=auto'
# Listing files in folder
alias listkb="ls -l --block-size=K"
alias listmb="ls -l --block-size=M"

## Colorize the grep command output for ease of use (good for log files)##
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

# Colorize diff output
alias diff='colordiff'

# Clipboard
alias cpy="xclip -selection clipboard"

# Start calculator with math support
alias bc="bc -l"

# Resume wget by default
alias wget="wget -c"

# ps Commands
alias ps="ps auxf"
# Get top process eating cpu
alias pscpu="ps auxf | sort -nr -k 3"
alias pscpu10="ps auxf | sort -nr -k 3 | head -10"
# Get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'

# Free and Used Ram
alias meminfo='free -l'
alias free='free -mt'

# Run top in alternate screen
alias top='tput smcup; top; tput rmcup'
And my bashrc:

Code: Select all

# ~/.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

# Added Options

# Powerline
. /usr/share/powerline/bindings/bash/powerline.sh

# Midnight Commander
. /usr/lib/mc/mc.sh

# ibus-typing-booster
#export GTK_IM_Module=ibus
#export XMODIFIERS=@im=ibus
#export QT_IM_Modules=ibus

# thefuck https://github.com/nvbn/thefuck
eval $(thefuck --alias)
# You can use whatever you want as an alias, like for Mondays:
# eval $(thefuck --alias ****)
# Experimental mode https://github.com/nvbn/thefuck#experimental-instant-mode
# eval $(thefuck --alias --enable-experimental-instant-mode)

# fzf https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh
# Info /usr/share/doc/fzf/README.Debian
# Enable fzf keybindings for Bash 
source /usr/share/doc/fzf/examples/key-bindings.bash
# Enable fuzzy auto-completion for Bash
#source /usr/share/doc/fzf/examples/completion.bash

# Fix PATH
PATH=$PATH:/home/pi/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/pi/.local/bin:

# yarn node package manager https://yarnpkg.com/
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

# nvm Nodejs version manager https://github.com/nvm-sh/nvm
. ~/.node_bashrc
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
Last edited by craigevil on 2022-02-25 15:27, edited 1 time in total.
Raspberry PI 400 Distro: Raspberry Pi OS Base: Debian Sid Kernel: 5.15.69-v8+ aarch64 DE: MATE Ram 4GB
Debian - "If you can't apt install something, it isn't useful or doesn't exist"
My Giant Sources.list

User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Re: Share Your BASH Aliases

#2 Post by edbarx »

I almost never used aliases. Terminals have a nice feature which allows me to navigate the history of commands. It is easy to use and helps me remember full commands.

Since .bash_history contains bash's command history, it is a good idea to occasionally backup this file for future reference. The other way is to use a large number for maximum number of saved commands.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

Bulkley
Posts: 6382
Joined: 2006-02-11 18:35
Has thanked: 2 times
Been thanked: 39 times

Re: Share Your BASH Aliases

#3 Post by Bulkley »

I don't use a DM so I use

Code: Select all

alias sx="startx"


After logging in I use sx to start X.

User avatar
RU55EL
Posts: 546
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Share Your BASH Aliases

#4 Post by RU55EL »

Code: Select all

alias cw.practice='morse -r -s -T -d -w 5 -F 25 -p 5 -E 0'
alias dir='dir --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -l'
alias ls='ls --color=auto'
alias pi='ssh pi@xx.xxx.xxx.xx'
alias temp='sudo sensors'
alias update='sudo apt update && sudo apt upgrade && apt moo && cowsay updates are done && cat /etc/debian_version && uname -r'
alias vdir='vdir --color=auto'

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: Share Your BASH Aliases

#5 Post by fabien »

Code: Select all

alias diff='diff --color=auto'
alias difff='diff --color=always --unified=3'
alias dwdiff='dwdiff --statistics --line-numbers --wdiff-output --color 2>&1'
alias ggrep='grep --color=auto'

# inhibit mc behaviour to cd pwd on exit
alias mc='. /usr/share/mc/bin/mc-wrapper.sh'

# less -R (interpret color esc.) -M (long prompt) -S (don't wrap long lines)
#      --follow-name (shift f follows same file name if name changes)
alias less='less -RM --follow-name'
alias zless='zless -RM'
alias lesss='less -RMS --follow-name'
alias zlesss='zless -RMS'

# sort ps aux by size and colorize output - takes one optional argument (grep pattern)
f_pss() {
   local FILTER="$1" P="[^ ]+ +" PSC="$(ps aux --sort=rss)" \
         D="\\x1b\\[0;90m" G0="\\x1b\\[0;32m" R0="\\x1b\\[0;31m" R1="\\x1b\\[1;31m" T="\\x1b\\[0m" W="\\x1b\\[1;37m"
   local P6="$P$P$P$P$P$P" HEADER="${PSC%%$'\n'*}"; HEADER="${HEADER/#/$'\n\e[4m'}" ### not FILTER="${1//./\\.}" on purpose
   [[ "$FILTER" ]] && PSC="$(grep -- "${FILTER//\\/\\\\}" <<<"$PSC"; :)" || :
   [[ "$PSSTAIL" == "doTail" ]] && PSC="$(tail -- <<<"$PSC")" || :

   perl -pe 's/^root +/'"$R0"'$&/; s/^'"$P"'/'"$G0"'$&/;
             s/(^'"$P"')('"$P"')('"$P"')('"$P"')('"$P6"')(.+$)/\1'"$W"'\2'"$T"'\3'"$R1"'\4'"$T"'\5\n\1'"$D"'\6'"$T"'/;
             s/(\n\x1b\[[[:digit:]];[[:digit:]]+m)(\x1b\[[[:digit:]];[[:digit:]]+m)?(.+\x1b\[0m$)/\n>StartOfLine2Brm<\3/;
             s/(>StartOfLine2Brm<)([^ ]+)/q[ ] x length $2/e' <<<"$PSC${HEADER/%/$'\e[0m\r\e[K\r\e[A'}"
             ### https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences
}
# sort ps aux by time and colorize output - takes one optional argument (grep pattern)
f_pst() {
   local FILTER="$1" P="[^ ]+ +" PSC="$(ps auxk -etime)" \
         D="\\x1b\\[0;90m" G0="\\x1b\\[0;32m" G1="\\x1b\\[1;32m" R0="\\x1b\\[0;31m" T="\\x1b\\[0m" W="\\x1b\\[1;37m"
   local P2="$P$P" P6="$P$P$P$P$P$P" HEADER="${PSC%%$'\n'*}"; HEADER="${HEADER/#/$'\n\e[4m'}"
   [[ "$FILTER" ]] && PSC="$(grep -v " ps auxk -etime$" <<<"$PSC" | grep -- "${FILTER//\\/\\\\}"; :)" \
                   || PSC="$(grep -v " ps auxk -etime$" <<<"$PSC")"
   [[ "$PSTTAIL" == "doTail" ]] && PSC="$(tail -- <<<"$PSC")" || :

   perl -pe 's/^root +/'"$R0"'$&/; s/^'"$P"'/'"$G0"'$&/;
             s/(^'"$P"')('"$P"')('"$P6"')('"$P"')('"$P"')(.+$)/\1'"$W"'\2'"$T"'\3'"$G1"'\4'"$T"'\5\n\1'"$D"'\6'"$T"'/;
             s/(\n\x1b\[[[:digit:]];[[:digit:]]+m)(\x1b\[[[:digit:]];[[:digit:]]+m)?(.+\x1b\[0m$)/\n>StartOfLine2Brm<\3/;
             s/(>StartOfLine2Brm<)([^ ]+)/q[ ] x length $2/e' <<<"$PSC${HEADER/%/$'\e[0m\r\e[K\r\e[A'}"
}
alias pss='PSSTAIL="" f_pss'
alias PSS='PSSTAIL="doTail" f_pss'
alias pst='PSTTAIL="" f_pst'
alias PST='PSTTAIL="doTail" f_pst'

# convert epoch format to human readable date
# convert human readable date to epoch format
f_epoch() {
   if [[ "$*" == +([0-9]) ]]; then
      ### e.g. epoch 1703088943
      date "--date=@$1"
   else
      ### e.g. epoch Wed. Dec 20 05:15:43 PM CET 2023
      ### e.g. epoch December 20 2023 CET 17:15:43
      ### e.g. epoch 2023-12-20 17:15:43 CET
      date --date="$*" +'%s'
   fi
}
alias epoch='f_epoch'

# colored list of all mounted filesystems
f_mnt() {
   ### e.g. mnt
   ### e.g. mnt "/dev/sda"
   ### e.g. mnt "[^─]+/dev/.+$"
   local uuid; declare -i fld
   "${WITHUUID:-false}" && fld=2 uuid=",UUID" || fld=1 uuid=""
   findmnt -o LABEL,TARGET,FSTYPE,SIZE,AVAIL,USED,USE%,SOURCE,VFS-OPTIONS"$uuid" --notruncate |\
   mawk -v rgxp="$1" '{if (NR==1){header="\x1b[0;1;94m"$0"\x1b[0m"; print "\n"header}
                       else {if ($0~rgxp){
                              if ($(NF-'"$fld"')~"^/"){sub (/\/dev\/[^ ]+/,"&\x1b[22;2m")
                                                       sub (/\/dev\/(mapper\/)?/,"&\x1b[1m")
                                                       print "\x1b[96m"$0"\x1b[0m"}
                              else {print "\x1b[94m"$0"\x1b[0m"}}}}
                      END {if (rgxp==""){print header"\n"} else {print ""}}'
}
alias mnt='WITHUUID="" f_mnt'
alias MNT='WITHUUID="true" f_mnt'

# display one or several files between FIRST and LAST line
f_zone() {
   ### e.g. zone 10 15 /etc/group /etc/passwd
   ### e.g. zcat /var/log/dpkg.log.2.gz | zone 5 10 /var/log/dpkg.log.1
   declare -a PIPED
   declare -i FIRST=1 LAST=10

   [[ "$1" =~ ^[0-9][0-9]*$ ]] && { FIRST=${1#0}; shift
                                    [[ "$1" =~ ^[0-9][0-9]*$ ]] && { LAST=${1#0}; shift; :
                                                              } || LAST=$FIRST FIRST=1; }
   ### https://serverfault.com/questions/156470/testing-for-a-script-that-is-waiting-on-stdin
   [[ -p /dev/stdin ]] && PIPED=( "-" )
   [[ -t 0 && -z "$@" ]] && { echo "${FUNCNAME[0]#f_}: usage: zone [FIRST] [LAST] [FILE]..."
                              return 0; }

   "$(command -v mawk || command -V mawk)" -v f=$FIRST -v l=$LAST \
    'FNR==1{print "\n\033[0;36m>>>>> "FILENAME"\033[0;35m from line "f" to "l"\033[0m" >"/dev/stderr"}
     FNR>=f && FNR<=l' "${PIPED[@]}" "$@"
}
alias zone='f_zone'

# output REGEXP protected pattern
f_protectRGXP() {
   local OPT="$1" PATTERN="$2" TEXT="$2" TP US
   declare -i ERR=0

   [[ "${3+set}" ]] && { OPT="Z"; set -- "Z" "Z" "Z"; }
   US="Usage: ${FUNCNAME[0]#f_} G|E|P|A|S|g|e|p|a|s \"PATTERN\"
       uppercase for pattern used in a variable, lowercase for direct use
       G: basic regexp (BRE), E: extended regexp (ERE), P: perl regexp (PCRE), A: awk, S: sed
       e.g. MYPATTERN=\"\$(protectRGXP G '*my.txt*' 2>/dev/null)\" && grep \"\$MYPATTERN\" /my/file"

   f_autotestRGXP() {
      local PATRNERR=$'\x1b[1;93m'"pattern error"$'\x1b[0m'
      case "$1" in
         G) grep -G --color=auto -- "$TP" <<<"G $TEXT G" || { ERR=1; echo "G grep: $PATRNERR G"; };;
         E) grep -E --color=auto -- "$TP" <<<"E $TEXT E" || { ERR=1; echo "E grep: $PATRNERR E"; };;
         P) grep -P --color=auto -- "$TP" <<<"P $TEXT P" || { ERR=1; echo "P grep: $PATRNERR P"; };;
         A) mawk '/'"$TP"'/{all=$0; sub (/'"$TP"'/," "); rest1=$1; rest2=$2; $0=all
                            $1=$NF=""; sub (/\/H/,"\\\\")
                            print rest1"\033[1;31m"$0"\033[0m"rest2; exit 0}
                  !/'"$TP"'/{print "A awk: '"$PATRNERR"' A"; exit 1}' <<<"A $TEXT A" || ERR=1;;
         S) local SEDMATCH="$(sed -n 's/'"$TP"'/\x1b[1;31m&\x1b[0m/p' <<<"S $TEXT S")"
            [[ "$SEDMATCH" ]] && printf '%s\n' "$SEDMATCH" || { ERR=1;echo "S sed: $PATRNERR S"; };;
         *) ERR=2; echo "${FUNCNAME[0]#f_}: internal error: invalid autotest option “${1:0:20}”";;
      esac
   }

   PATTERN="${PATTERN//\\/\\\\}"
   [[ "$OPT" == [egp] ]] && PATTERN="${PATTERN//\\/\\\\}" PATTERN="${PATTERN//\`/\\\`}" \
                            PATTERN="${PATTERN//\"/\\\"}"
   PATTERN="${PATTERN//./\\.}" PATTERN="${PATTERN//\*/\\\*}"
   PATTERN="${PATTERN//\[/\\[}" PATTERN="${PATTERN//\]/\\]}"
   PATTERN="${PATTERN//^/\\^}" PATTERN="${PATTERN//$/\\$}" PATTERN="${PATTERN//!/\\!}"

   case "${OPT^^}" in
        G) printf '\n%s\n' $'\e[0;2m'"$TEXT"$'\e[0m' >&2
           [[ "$OPT" == "g" ]] && PATTERN="${PATTERN/%\\$/\\\\$}";;
      E|P) printf '\n%s\n' $'\e[0;2m'"$TEXT"$'\e[0m' >&2
           PATTERN="${PATTERN//\?/\\\?}" PATTERN="${PATTERN//|/\\|}" PATTERN="${PATTERN//+/\\+}"
           PATTERN="${PATTERN//\(/\\\(}" PATTERN="${PATTERN//\)/\\\)}"
           PATTERN="${PATTERN//\{/\\\{}" PATTERN="${PATTERN//\}/\\\}}"
           [[ "$OPT" == [ep] ]] && PATTERN="${PATTERN//\\$/\\\\\\$}";;
        A) printf '\n%s\n' $'\e[0;2m'"$TEXT"$'\e[0m' >&2
           PATTERN="${PATTERN//|/\\|}" PATTERN="${PATTERN//\//\\\/}" PATTERN="${PATTERN//\?/\\\?}"
           PATTERN="${PATTERN//\(/\\\(}" PATTERN="${PATTERN//\)/\\\)}" PATTERN="${PATTERN//+/\\+}"
           [[ "$OPT" == "a" ]] && PATTERN="${PATTERN//\'/\'\"\'\"\'}";;
        S) printf '\n%s\n' $'\e[0;2m'"$TEXT"$'\e[0m' >&2
           PATTERN="${PATTERN//\//\\\/}"
           [[ "$OPT" == "s" ]] && PATTERN="${PATTERN//\'/\'\"\'\"\'}";;
        *) {
           [[ "$3" ]] && { echo $'\e[0m\n'"${FUNCNAME[0]#f_}: too many arguments"; ERR=1 OPT=""; }
           [[ "$OPT" ]] && { echo $'\e[0m\n'"${FUNCNAME[0]#f_}: unknown option “${OPT:0:30}”"; ERR=1; }
           TEXT="\ . * ] [ ' \" \` ^ $ | + ? ) ( \R / } { {9} = ! > < : - #"
           echo -e "\e[0m\n$US\n\nautotest: \e[0;31m$TEXT\e[0m"
           TP="$(f_protectRGXP G "$TEXT" 2>/dev/null)"
           printf '%s' "PATTERN> $(declare -p TP | cut -d'=' -f2-)" $'\n'"        "
           f_autotestRGXP "G"
           TP="$(f_protectRGXP E "$TEXT" 2>/dev/null)"
           printf '%s' "PATTERN> $(declare -p TP | cut -d'=' -f2-)" $'\n'"        "
           f_autotestRGXP "E"; echo -n "        "; f_autotestRGXP "P"
           TP="$(f_protectRGXP A "$TEXT" 2>/dev/null)"
           printf '%s' "PATTERN> $(declare -p TP | cut -d'=' -f2-)" $'\n'"        "
           f_autotestRGXP "A"
           TP="$(f_protectRGXP S "$TEXT" 2>/dev/null)"
           printf '%s' "PATTERN> $(declare -p TP | cut -d'=' -f2-)" $'\n'"        "
           f_autotestRGXP "S"
           echo; } >&2; return $ERR;;
   esac
   [[ "$OPT" == [aegps] ]] && echo -en "\n\e[1;36m-->\e[0;37m\"\e[0m" >&2 \
                           || echo -en "\n\e[0;37m-->\e[0m" >&2
   printf '%s' "$PATTERN"
   [[ "$OPT" == [aegps] ]] && echo -e "\e[0;37m\"\e[1;36m<--\e[0m\n" >&2 \
                           || echo -e "\e[0;37m<--\e[0m\n" >&2
   [[ "${FUNCNAME[1]}" == "${FUNCNAME[0]}" || "$OPT" != [GEPAS] || -z "$PATTERN" ]] && return $ERR
   { printf '%s' $'\e[1;36m'"-->"$'\e[0m' "$(declare -p PATTERN | cut -d'=' -f2- |\
                                                                  sed 's/^"\|"$/\x1b[0;37m&\x1b[0m/g')" \
                 $'\e[1;36m'"<--"$'\e[0m'
     TP="$PATTERN"; printf '\n\n%s' "Pattern autotest: "; f_autotestRGXP "$OPT"; echo; } >&2
   return $ERR
}
alias protectRGXP='f_protectRGXP'

I add my prompt:
- special prompt if under mc (midnight commander)
- 1st line: empty
- 2nd line: prompt (with last command exit code)
- 3rd line: command
- 4th line: empty (PS0='\n')

Code: Select all

if [ "$color_prompt" = yes ]; then
   [[ "$MC_TMPDIR" ]] && {
    PS1='\n${debian_chroot:+($debian_chroot)}\[\e[0;37m\][$?] \[\e[0;90m\]\D{%a %-d %b} \t ⚛ \[\e[1;38;5;242;48;5;21m\][\u@\h:\w]\$\[\e[0m\] \n'
    } || {
    PS1='\n${debian_chroot:+($debian_chroot)}\[\e[0;37m\][$?] \[\e[0;90m\]\D{%a %-d %b} \t ⚛ \[\e[1;30m\][\u@\h:\w]\$\[\e[0m\] \n'; }
   PS0='\n'
else
   PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
And 'less' color tweaks:

Code: Select all

   (( $(tput colors) >= 255 )) && LESS_TERMCAP_us=$'\e[0;37m' || LESS_TERMCAP_us=$'\e[0;36m'
   export GROFF_NO_SGR=1                  # needed since groff 1.23.0-1 trixie/testing for manuals
   export LESS_TERMCAP_md=$'\e[1;33m'     # begin bold
   export LESS_TERMCAP_us                 # begin underline
   export LESS_TERMCAP_so=$'\e[0;96;44m'  # begin standout-mode - info box - search results
   export LESS_TERMCAP_me=$'\e[0m'        # end bold/blink
   export LESS_TERMCAP_ue=$'\e[0m'        # end underline
   export LESS_TERMCAP_se=$'\e[0m'        # end standout-mode
edits: [2022-03-12] revised pss and pst aliases, added epoch alias. [2022-10-12] added mnt alias. [2022-11-19] added zone and protectRGXP aliases. [2022-12-04] revised protectRGXP alias. [2023-01-07] slightly revised zone and protectRGXP aliases. [2023-04-29] revised pss and pst aliases. slightly revised protectRGXP alias. [2023-04-30] revised pss and pst aliases, added PSS and PST aliases. [2023-06-04] revised mnt alias. [2023-06-14] revised mnt alias. [2023-06-18] revised protectRGXP alias. [2023-09-14] revised mnt alias. [2023-11-06] added MNT alias. [2024-02-24] revised epoch alias.
Last edited by fabien on 2023-11-06 12:46, edited 15 times in total.

sirfer
Posts: 32
Joined: 2013-05-15 23:13
Location: Auckland, New Zealand
Has thanked: 14 times
Been thanked: 2 times

Re: Share Your BASH Aliases

#6 Post by sirfer »

It's not an alias, but I'll share anyway as it saves me a lot of typing when doing updates. I run testing and sid from the same boot drive so like to update often...

Code: Select all

#!/bin/bash
apt update && 
apt dist-upgrade && 
apt autoremove --purge && 
apt autoclean
I used to use sx for startx as well but now just use 'x'

User avatar
craigevil
Posts: 5391
Joined: 2006-09-17 03:17
Location: heaven
Has thanked: 28 times
Been thanked: 39 times

Re: Share Your BASH Aliases

#7 Post by craigevil »

sirfer wrote: 2022-02-25 11:09 It's not an alias, but I'll share anyway as it saves me a lot of typing when doing updates. I run testing and sid from the same boot drive so like to update often...

Code: Select all

#!/bin/bash
apt update && 
apt dist-upgrade && 
apt autoremove --purge && 
apt autoclean
I used to use sx for startx as well but now just use 'x'
I have started using Nala, by default it uses full-upgrade and does autoremove.
So all I have to type in a terminal is update.
Raspberry PI 400 Distro: Raspberry Pi OS Base: Debian Sid Kernel: 5.15.69-v8+ aarch64 DE: MATE Ram 4GB
Debian - "If you can't apt install something, it isn't useful or doesn't exist"
My Giant Sources.list

user6c57b8
Posts: 19
Joined: 2022-05-31 16:19
Has thanked: 5 times

Re: Share Your BASH Aliases

#8 Post by user6c57b8 »

Code: Select all

alias bash++='/usr/bin/perl'   #0% useful, 13% funny
alias battery='echo acpitool -b'
alias bitchx='/usr/bin/weechat -a -p --plugins irc,logger,alias,exec' #no auto-connect to a server and no plug-ins automatically loaded
alias ..='cd ..'
alias check-network='bash -c "ip route; curl -IL http://nmcheck.gnome.org/check_network_status.txt"'
alias df='df --human-readable --print-type 2>/dev/null'
alias ffmpeg='/usr/bin/ffmpeg -hide_banner'
alias ffplayer=ffplay
alias ffprobe='/usr/bin/ffprobe -hide_banner'
alias jpeg='/usr/bin/jpegoptim -s'
alias myip='bash -c "wget --quiet -O - -4 ifconfig.io; wget --quiet -O - -6 ifconfig.io"'
alias png='/usr/bin/optipng'
alias suspend='echo systemctl suspend' #when I actually do want to 'suspend' I go:    `suspend`
alias tree='/usr/bin/tree -A'
alias tty-exec-desktop-program='echo "DISPLAY=:0.0 google-chrome http://people.oregonstate.edu"' #I use this as a reference rather than actual application
alias tty-silence-restore='sudo dmesg -n 8'
alias tty-silence='sudo dmesg -n 1'
alias udisks='/usr/bin/udisksctl'
alias vi='/usr/bin/vim'
alias weechat='echo bitchx' #gotta remember the "real" name of my installed IRC client xD

User avatar
wizard10000
Global Moderator
Global Moderator
Posts: 551
Joined: 2019-04-16 23:15
Location: southeastern us
Has thanked: 75 times
Been thanked: 85 times

Re: Share Your BASH Aliases

#9 Post by wizard10000 »

I've only got a couple -

Code: Select all

alias upgrade="sudo aptitude update && sudo aptitude full-upgrade"
alias syncinternal="sudo time sh -c /usr/local/sbin/syncinternal"
alias backup="sudo /bin/sh /usr/local/sbin/backup"
That syncinternal script is one that syncs an internal 2TB drive to two identical external 2TB drives if I need to do it outside of a scheduled backup job.

edit: Haven't seen it mentioned here but I also use Ctrl-R in bash to search my history. Just hit Ctrl-R and start typing a command and bash will try to match what you're typing from .bash_history. If the first hit isn't the correct command just hit Ctrl-R again to continue the search.

edit v2.0: @craigevil - I used nala for a bit and really liked it. I went back to aptitude the first time nala offered to remove a bunch of my system without offering suggestions :mrgreen:
we see things not as they are, but as we are.
-- anais nin

User avatar
limotux
Posts: 148
Joined: 2011-05-30 17:38
Has thanked: 35 times
Been thanked: 11 times

Re: Share Your BASH Aliases

#10 Post by limotux »

craigevil wrote: 2022-02-25 15:23
sirfer wrote: 2022-02-25 11:09 It's not an alias, but I'll share anyway as it saves me a lot of typing when doing updates. I run testing and sid from the same boot drive so like to update often...

Code: Select all

#!/bin/bash
apt update && 
apt dist-upgrade && 
apt autoremove --purge && 
apt autoclean
I used to use sx for startx as well but now just use 'x'
I have started using Nala, by default it uses full-upgrade and does autoremove.
So all I have to type in a terminal is update.
Thanks for sharing this @craigevil
I will appreciate if you give me feedback about your experience.
Is this script OK with stable release?
Does it upgrade from one release to the next?
My detailed question is in this thread I just made viewtopic.php?t=156053
I hope you can help.
Thank you
Debian 12 (bookworm), KDE Plasma, quad core Intel Core i7-8550U
Drives: 238.47 GiB SSD
Memory: 7690.7 MiB
(Installed 24/8/2023) (no techie)

sarge
Posts: 6
Joined: 2019-04-23 12:35
Been thanked: 1 time

Re: Share Your BASH Aliases

#11 Post by sarge »

Code: Select all

alias tm="tmux attach-session || tmux new-session"
This will re-attach an existing session, or create a new session if one doesn't exist. That way I don't need to think about whether I have a session already or not. I never use more than one session at once so this works great for me.

Code: Select all

alias alu='apt list --upgradable'
Saves some typing after an apt update.

m4c-attack
Posts: 23
Joined: 2023-10-09 05:06
Has thanked: 34 times
Been thanked: 2 times

Re: Share Your BASH Aliases

#12 Post by m4c-attack »

Here's a similar thread that I came across:

https://kbin.social/m/linux@lemmy.ml/t/ ... -you-using

Post Reply