might be useful to others, and to start a collection-type thread where others could also post their .bashrc or snippets of it with explanations
so everyone could grab a bit here and there.
For those that don't know, .bashrc is a hidden settings file, which gets sourced (executed) everytime you open
a terminal (for a user which has it's shell set to bash, which is the default in Mageia) so you have all your custom
settings, nice little shortcuts, color and prompt definitions and such, in additions to the systemwide one in /etc/bashrc.
For some explanations about bash, aliases, functions and other things discussed here, you may want to have a look at the following links beforehand:
The Linux Documentation Project - Bash Guide for Beginners
Advanced Bash-Scripting Guide - Aliases
Advanced Bash-Scripting Guide - Functions
Bash Guide for Beginners - What are aliases?
And FWIW, you can show the currently enabled aliases via alias command and you can also temporarily unset one alias via the unalias command, analogue to the handling of environment variables.
This is mine (i don't have more stuff in there as normally i don't connect to other boxes from my workstation, and don't need no advanced/intelligent prompt definitions, colourprompt and the default Mageia prompt definition is just fine for me)
- Code: Select all
[doktor5000@Mageia2 ~]$ cat .bashrc
# .bashrc
# User specific aliases and functions
function ufn() {
urpmf -f -m --name "$@" | sort
}
function rg() {
rpm -qa | grep -i "$@" | sort
}
alias uq='urpmq -a'
alias ri='rpm -qi'
alias rq='rpm -q --requires'
alias rp='rpm -q --provides'
alias ua='sudo urpmi.update -av'
alias ub='sudo urpmi --buildrequires'
alias up='sudo urpmi'
alias mvn='mv ~/rpm/RPMS/noarch/*.rpm ~/rpm/RPMS/x86_64'
alias ra='rpm --addsign ~/rpm/RPMS/x86_64/*.rpm && rpm --addsign ~/rpm/SRPMS/*.rpm'
alias rb='rpmbuild -ba --clean'
alias re='rpmbuild --rebuild'
alias rba='rpmbuild -ba --clean --sign'
alias rbi='rpmbuild -bi --short-circuit'
alias rbp='rpmbuild -bp'
alias rbc='rpmbuild -bc --short-circuit'
alias dv='desktop-file-validate'
alias sudo='sudo -E'
alias be='sudo urpmi.update --no-ignore backports && sudo urpmi.update -av'
alias bd='sudo urpmi.update --ignore backports'
alias te='sudo urpmi.update --no-ignore testing && sudo urpmi.update -av'
alias td='sudo urpmi.update --ignore testing'
alias de='sudo urpmi.update --no-ignore debug && sudo urpmi.update -av'
alias dbgd='sudo urpmi.update --ignore debug'
alias scc='sudo LC_ALL=C mcc'
alias mdb='mgarepo maintdb get'
#SVN stuff
export EDITOR=kwrite
#PHONON_PULSEAUDIO_DEBUG=3
#KMIX_PULSEAUDIO_DEBUG=3
#export PHONON_VLC_DEBUG=3
#export PHONON_DEBUG=1
HISTSIZE=100000
shopt -s histappend
PROMPT_COMMAND='history -a'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
Some explanations for the more interesting ones:
- Code: Select all
function ufn() {
urpmf -f -m --name "$@" | sort
}
Previously i also had this as an alias, but as i wanted the results to be sorted, this is not possible with aliases AFAIK, so now this is a functions.
Searches all currently enabled repositories for a given package name or part of a name, and shows the full name and version information, together with the media information (in which repository a package is located) - the results are alphabetically sorted --> this is quite useful, and i use it extensively
- Code: Select all
function rg() {
rpm -qa | grep -i "$@" | sort
}
Searches in the names of all installed packages for a given string (name, part of a name, version) and ignores case sensitivity, displays the results alphabetically sorted --> this is quite useful, and i use it extensively
- Code: Select all
alias up='sudo urpmi'
Due to my sudo setup --> this is quite useful, and i use it extensively
- Code: Select all
alias sudo='sudo -E'
This one is interesting, since quite some time some of the drakxtools only open the ncurses-based version when launched from a terminal, this was probably caused by some change of the default sudo setup or the upstream sudo configuration. -E preserves environment variables of the current user for the sudo environment.
- Code: Select all
alias be='sudo urpmi.update --no-ignore backports && sudo urpmi.update -av'
alias bd='sudo urpmi.update --ignore backports'
alias te='sudo urpmi.update --no-ignore testing && sudo urpmi.update -av'
alias td='sudo urpmi.update --ignore testing'
alias de='sudo urpmi.update --no-ignore debug && sudo urpmi.update -av'
alias dbgd='sudo urpmi.update --ignore debug'
Those can be quite handy. Those that end with an "e" enable the according repositories, and update the hdlists, those that end with a "d" disable the according repositories. Quite useful if you need to handle testing, backports or debug media and makes it easier f.ex. to only selectively install something from repositories, which was best-practice when dealing with backports repositories under Mandriva.
- Code: Select all
alias scc='sudo LC_ALL=C mcc'
Only saves some repetitive typing, this one enables me to easily launch Mageia Control Center in english, as i need the names of the menu points and stuff like that in english for support reasons. It is also best practice to prefix any command by LC_ALL=C if it gives non-english output
- Code: Select all
rpm -qa --qf "%{SIZE}\t%{NAME}-%{VERSION}\n" | sort -rn
This one is not in my bashrc, as i actually never really need it, but it may be quite useful to some. It queries all installed packages, and lists them by their size, in descending order.
- Code: Select all
HISTSIZE=100000
shopt -s histappend
PROMPT_COMMAND='history -a'
Those belong together, and they are golden for me. It raises the size of the shell history, and the two latter definitions set up the history in such a way that the history from every open terminal session gets appended live to the shell history, and does not get overwritten. Really handy if you use the history command or Ctrl+R (recursive history search in bash) to search for commands thatyou run already some time ago.
More bashrc magic:
What useful things can one add to one's .bashrc?
Show us your .bashrc! - thread in ubuntuforums.org
shell-fu.org bashrc
The Ultimate Bashrc File at gnome-look.org