You are not logged in.
A lot of this is borrowed from other sites, including the wiki
This by no means all-inclusive, please add on anything interesting along this topic
About ~/.bash_profile and ~/.bashrc
disclaimer: I don't use ~/.bash_profile or ~/.profile
there is plenty of documentation on the web on how to use these properly if you're interested
in fact, my ~/.bash_profile looks like this:
#!/bin/sh
### THIS IS A DUMMY FILE
### DON'T NEED TWO FILES TO DO ONE JOB
### LET'S CALL ~/.bashrc INSTEAD
source ~/.bashrc
Now, if you choose to go this method, there's a little trick you can do to eliminate ~/.bash_profile altogether :twisted:
as root create file /etc/profile.d/bashrc.sh with contents:
#!/bin/sh
source ~/.bashrc
AND
chmod +x /etc/profile.d/bashrc.sh
Since /etc/profile executes everything in /etc/profile.d/ that is chmod executable, the little script we just created will cause ~/.bashrc to be read on every login... I personally prefer this method to the dummy ~/.bash_profile, but I keep both since I share my /home directory across distributions and not all distros are the same.
Now, on to the actual ~/.bashrc:
#!/bin/sh
### ALIASES
alias ls="ls --color"
alias ll="ls --color -lh"
alias la="ls --color -a"
alias pacs="pacsearch"
alias vim="vim -y"
alias nano="nano -w"
### NICE COLOR BASH PROMPT
function bash_prompt
{
local WHITE="[33[1;37m]"
local default="[33[0;39m]"
local BRIGHTGREEN="[33[1;32m]"
local GREEN="[33[0;32m]"
local CYAN="[33[0;36m]"
local GRAY="[33[0;37m]"
local RED="[33[0;31m]"
if [ `id -u` != "0" ]; then
PS1="${GREEN}u${CYAN}@${GREEN}h ${CYAN}w${WHITE} ${default}$ "
else
PS1="${RED}u${CYAN}@${GREEN}h ${CYAN}w${WHITE} ${default}$ "
fi
}
bash_prompt
### COLORIZE PACMAN (PACS)
pacsearch () {
echo -e "$(pacman -Ss $@ | sed
-e 's#current/.*#\033[1;31m&\033[0;37m#g'
-e 's#extra/.*#\033[0;32m&\033[0;37m#g'
-e 's#community/.*#\033[1;35m&\033[0;37m#g'
-e 's#^.*/.* [0-9].*#\033[0;36m&\033[0;37m#g' )"
}
This is really pretty basic. I use the same ~/.bashrc for all users, including root...
The alias section is pretty self explanatory, basically the parts in quotations (" ") get run instead of the commands before the equals (=) in every case.
The bash prompt section is a bit nifty. The first part, with color definitions, is so that I don't go mad trying to write the actual PS1 line. Makes it cleaner in my opinion. There's lots of documentation out there if you're interested in modifying the prompt I have.
The if/then/else statement in the bash prompt section checks if the user is root. If not, the username is displayed in GREEN at the prompt. If the user is root, the username is displayed in RED. A nice visual reminder, and since I use my ~/.bashrc for ALL users, including root, it helps make the file more portable.
The last section is taken straight from the Arch wiki. At the top I aliased 'pacs', which calls this section. Basically 'pacs' can take the place of 'pacman -Ss' and offer simple colour output.
http://wiki.archlinux.org/index.php/Col … man_output
Additions, other bash tips & tricks, comments, all welcome
Offline
in fact, my ~/.bash_profile looks like this:
#!/bin/sh ### THIS IS A DUMMY FILE ### DON'T NEED TWO FILES TO DO ONE JOB ### LET'S CALL ~/.bashrc INSTEAD source ~/.bashrc
I prefer to symlink bash_profile to bashrc
Offline
I need to be in this thread!
*Find back post*
A bus station is where a bus stops.
A train station is where a train stops.
On my desk I have a workstation.
Offline
Is it allowed to paste stuff that was copied from other members of this forum?
I found this one on rezza's configs. It makes extraction of compressed files easier. Of course to be put in .bashrc
ex () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
Again: this one is not from me, but rezza!!
Offline
In addition to that same function ganked from rezza, I have a handful of little functions in my bashrc:
(note: hex2dec and dec2hex removed because they broke... I'll fix them later)
function calc() { echo "$*" | bc; }
function mktar() { tar czf "${1%%/}.tar.gz" "${1%%/}/"; }
function mkmine() { sudo chown -R ${USER} ${1:-.}; }
function newmail()
{
tot=0
for mb in $MAIL/*; do
cnt=`ls -1 $mb/new/|wc -l`
tot=`expr $tot + $cnt`
echo "$(basename $mb):$cnt"
done
echo "Total:$tot"
}
This one is my favorite... i use vim alot, so I find myself trying to use vim commands in the bash shell sometimes:
:h() { vim --cmd ":silent help $@" --cmd "only"; }
I also used to have:
:q() { exit }
Offline
I added some comments explaining each piece.
Misc stuff:
# My prompt, quite basic, decent coloring, shows the value of $?
# (exit value of last command, useful sometimes):
C_DEFAULT="[33[0m]"
C_BLUE="[33[0;34m]"
export PS1="$C_BLUE($C_DEFAULT$?$C_BLUE)[$C_DEFAULTu$C_BLUE@$C_DEFAULTh$C_BLUE:$C_DEFAULTw$C_BLUE]\$ $C_DEFAULT"
export PS2="$C_BLUE> $C_DEFAULT"
# If you allow Ctrl+Alt+Backspace to kill the X server but are paranoid,
# then this alias will ensure that there will be no shell open afterwards.
alias startx="exec startx"
# Let grep colorize the search results
alias g="egrep --color=always"
alias gi="egrep -i --color=always"
# Hostname appended to bash history filename
export HISTFILE="$HOME/.bash_history_`hostname -s`"
# Don't save repeated commands in bash history
export HISTCONTROL="ignoredups"
# Confirm before overwriting something
alias cp="cp -i"
# Disable ^S/^Q flow control (does anyone like/use this at all?)
stty -ixon
# If your resolution gets fucked up, use this to reset (requires XRandR)
alias resreset="xrandr --size 1280x1024"
And some small but handy functions:
# mkmv - creates a new directory and moves the file into it, in 1 step
# Usage: mkmv <file> <directory>
mkmv() {
mkdir "$2"
mv "$1" "$2"
}
# sanitize - set file/directory owner and permissions to normal values (644/755)
# Usage: sanitize <file>
sanitize() {
chmod -R u=rwX,go=rX "$@"
chown -R ${USER}.users "$@"
}
# nh - run command detached from terminal and without output
# Usage: nh <command>
nh() {
nohup "$@" &>/dev/null &
}
# run - compile a simple c or cpp file, run the program, afterwards delete it
# Usage: run <file> [params]
run() {
filename="${1%%.*}"
extension="${1##*.}"
file="$1"
shift
params="$@"
command=""
if [ $extension = "cc" -o $extension = "cpp" -o $extension = "c++" ]; then
command="g++"
elif [ $extension = "c" ]; then
command="gcc"
else
echo "Invalid file extension!"
return 1
fi
$command -Wall -o $filename $file
chmod a+x $filename
./$filename $params
rm -f $filename 2>/dev/null
}
Offline
# Disable ^S/^Q flow control (does anyone like/use this at all?) stty -ixon
Awesome! Thanks
Offline
I need to be in this thread!
*Find back post*
yeah me too
Offline
palandir wrote:# Disable ^S/^Q flow control (does anyone like/use this at all?) stty -ixon
Awesome! Thanks
What the smeg does that mean? *feels left out*
.oO Komodo Dave Oo.
Offline
The only useful thing I have is this:
alias pacman="sudo pacman"
It's simple. It lacks teh bling. But I'm tired of typing sudo pacman.
Offline
Nothing fancy here either, just a bunch of aliases to save keystrokes:
alias swanstart='sudo /etc/rc.d/openswan start'
alias swanrestart='sudo /etc/rc.d/openswan restart'
alias swanstop='sudo /etc/rc.d/openswan stop'
alias swanstatus='sudo /etc/rc.d/openswan status'
alias nfs='sudo /etc/rc.d/netfs'
alias pg='ps ax | grep'
alias pss='pacman -Ss'
alias pq='pacman -Q | grep'
alias pi='pacman -Qi'
alias pl='pacman -Ql'
alias po='pacman -Qo'
alias pacman='sudo pacman'
alias bear='sudo /usr/sbin/hibernate'
alias eject='eject /cdrom'
alias tarpkg='tar czf `pwd | cut -d "/" -f 5`.tar.gz PKGBUILD'
alias mymp='mplayer -fs -stop-xscreensaver -cache 8192'
What the smeg does that mean? *feels left out*
Me too - &%$£ing geeks ........:P
Offline
IMHO this thread should be wikified.
to live is to die
Offline
phrakture wrote:palandir wrote:# Disable ^S/^Q flow control (does anyone like/use this at all?) stty -ixon
Awesome! Thanks
What the smeg does that mean? *feels left out*
Yay nested quotes!
Try hitting CTRL-S in a bash term, type a bunch of stuff, then hit CTRL-Q; you'll see what it does.
Offline
IMHO this thread should be wikified.
Then add it to the wiki! Youu... haavveee.... the POWAAA! (lame He-Man reference)
Offline
Where we are at pacman aliases
#Pacman shortcuts
alias p="pacman"
alias pQ="pacman -Q"
alias pqs="pacman -Qs"
alias pqi="pacman -Qi"
alias pS="sudo pacman -S"
alias psyu="sudo pacman -Syu"
alias psi="pacman -Si"
alias pR="sudo pacman -R"
alias prc="sudo pacman -Rc"
alias prs="sudo pacman -Rs"
alias prsc="sudo pacman -Rsc"
alias pA="sudo pacman -A"
alias pU="sudo pacman -U"
alias pO="sudo pacman-optimize"
#Colorful pacman -Ss output
pss () {
echo -e "$(pacman -Ss $@ | sed
-e 's#current/.*#\033[1;31m&\033[0;37m#g'
-e 's#extra/.*#\033[0;32m&\033[0;37m#g'
-e 's#community/.*#\033[1;35m&\033[0;37m#g'
-e 's#^.*/.* [0-9].*#\033[0;36m&\033[0;37m#g' )"
}
scnr
Offline
#Colorful pacman -Ss output
pss () {
echo -e "$(pacman -Ss $@ | sed
-e 's#current/.*#\033[1;31m&\033[0;37m#g'
-e 's#extra/.*#\033[0;32m&\033[0;37m#g'
-e 's#community/.*#\033[1;35m&\033[0;37m#g'
-e 's#^.*/.* [0-9].*#\033[0;36m&\033[0;37m#g' )"
}
$ pss xfce4-svn
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
xfce-svn/xfce4-pluginpack-svn 0.0.5-1
Xfce4 panel plugins, ported to Xfce4-svn panel
Ok, who broke my bash and sed?
Offline
Try hitting CTRL-S in a bash term, type a bunch of stuff, then hit CTRL-Q; you'll see what it does.
Ah, I knew that actually... I do it all the time -_- It's well irritating, so that tidy bash nibblet will be mighty useful
.oO Komodo Dave Oo.
Offline
#Colorful pacman -Ss output pss () { echo -e "$(pacman -Ss $@ | sed -e 's#current/.*#\033[1;31m&\033[0;37m#g' -e 's#extra/.*#\033[0;32m&\033[0;37m#g' -e 's#community/.*#\033[1;35m&\033[0;37m#g' -e 's#^.*/.* [0-9].*#\033[0;36m&\033[0;37m#g' )" }
Ok, who broke my bash and sed?
pacsearch () {
echo -e "$(pacman -Ss $@ | sed
-e 's#current/.*#\033[0;31m&\033[0;37m#g'
-e 's#extra/.*#\033[0;32m&\033[0;37m#g'
-e 's#community/.*#\033[0;35m&\033[0;37m#g'
-e 's#^.*/.* .*#\033[0;36m&\033[0;37m#g')e[m"
..spot the difference
.oO Komodo Dave Oo.
Offline
no spotting
... and the "pss" vs "pacsearch" is not the solution.
Offline
no spotting
... and the "pss" vs "pacsearch" is not the solution.
lol! I didn't see a difference tbh, i just thought if you tried the one rezza has, it might work unlucky man :shock:
.oO Komodo Dave Oo.
Offline
no spotting
... and the "pss" vs "pacsearch" is not the solution.
Might be a problem with copy&paste. Check that there are no spaces after '' at the end of every line that seems to end with a ''.
Offline
It would be handy if someone wrote a couple of functions for renaming things...
You could have 'rename [current file extension] [desired file extension]' which would perform
`ls -d | sed 's:(.*)$1:mv "&" "1$2"' | sh`
...or _possibly_ a similar command that removes any completely intentional errors I've included in there (it's late, I'm tired, so shoot me -_-).
.oO Komodo Dave Oo.
Offline
Check that there are no spaces after '' at the end of every line
Ups :oops: Thanks sh__ you fixed my bash and sed
Offline
It would be handy if someone wrote a couple of functions for renaming things...
You could have 'rename [current file extension] [desired file extension]' which would perform
`ls -d | sed 's:(.*)$1:mv "&" "1$2"' | sh`
...or _possibly_ a similar command that removes any completely intentional errors I've included in there (it's late, I'm tired, so shoot me -_-).
If you know Perl's regular expressions and the s/// function, then you can also use rename. I use it quite often, it's really great, and it's a bit easier to use than forming long bash one-liners with sed.
For example, to lower-case everything, type:
rename -c *
And your example above could be done with:
rename 's/.ext$/.newext/' file.ext
If you do the same thing often you can also alias that.
There are more examples on the page or in the perldoc.
Another cool thing is that you aren't limited to s///, you can use any Perl code, and as many instructions separated by ';' you like, because it gets eval()ed.
And, of course, there's a preview option.
Offline
If you know Perl's regular expressions and the s/// function, then you can also use rename. I use it quite often, it's really great, and it's a bit easier to use than forming long bash one-liners with sed.
Giggidy, useful info there, cheers palandir
.oO Komodo Dave Oo.
Offline