You are not logged in.

#26 2006-06-02 20:22:00

sesser
Member
From: NorCal
Registered: 2005-11-02
Posts: 20
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

postlogic wrote:

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.

I feel your pain. I did this a while ago me self.

Offline

#27 2006-06-03 11:34:15

rezza
Member
From: Edinburgh, uk
Registered: 2004-07-08
Posts: 237

Re: basic ~/.bashrc ~/.bash_profile tips thread

# rezza's .bashrc
# Most recent update: Sat 03 Jun 2006 12:31:58 BST

[ -z "$PS1" ] && return

# Basic options
export HISTCONTROL=ignoredups
export COLORFGBG='default;default'

shopt -s checkwinsize
eval "$(dircolors -b /etc/dircolors)"

# Aliases
alias ls='ls -h --color=auto'
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias svim='sudo vim'
alias h='cd'
alias ..='cd ..'
alias cd..='cd ..'
alias ...='cd ../..'
alias cim='vim'
alias back='cd $OLDPWD'
alias root='sudo su'
alias runlevel='sudo /sbin/init'
alias grep='grep --color=auto'
alias omg='ssh alpha.hostingbeyond.co.uk'
alias oszen='ssh os-zen.net'
alias data='ssh neit.datasysinte.info'
alias dfh='df -h'
alias gvim='gvim -geom 84x26'
alias update='sudo pacman -Syu'
alias mpdupdate='aurbuild -b mpd-svn mpc-svn libmpd-svn gmpc-svn'
alias start='dbus-launch startx'

# Prompt
PS1='[33[0;34m]([33[0;31m]w[33[0;34m]) [33[00m]h [33[0;31m]$ [33[00m]'

# Paths
PATH=$PATH:${HOME}/bin:/usr/lib/wine/bin:/sbin:/usr/sbin
export PATH=$PATH:/usr/local/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/wine/lib:/usr/local/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

# X Terminal titles
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "33]0;${USER}@${HOSTNAME}: ${PWD}07"'
    ;;
*)
    ;;
esac

# Functions
extract () {
    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    ;;
            *)            echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}
ziprm () {
    if [ -f $1 ] ; then
        unzip $1
        rm $1
    else
        echo "Need a valid zipfile"
    fi
}
psgrep() {
    if [ ! -z $1 ] ; then
        echo "Grepping for processes matching $1..."
        ps aux | grep $1 | grep -v grep
    else
        echo "!! Need name to grep for"
    fi
}
grab() {
    sudo chown -R ${USER} ${1:-.}
}

# Coloured Pacman searching
pacs () {
    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' )"
}

# Bash completion
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# Locale and editor
export EDITOR=vim
export BROWSER="epiphany '%s' &"

Offline

#28 2006-06-04 11:29:18

drakosha
Member
Registered: 2006-01-03
Posts: 253
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

2 minor comments:
1. for "psgrep" there's "pgrep" command. There's also "pkill" BTW smile.
2. for "extract" there's nice tool named "atool" (available in AUR)

Offline

#29 2006-06-04 12:02:09

phildg
Member
Registered: 2006-03-10
Posts: 146

Re: basic ~/.bashrc ~/.bash_profile tips thread

palandir wrote:
# Disable ^S/^Q flow control (does anyone like/use this at all?)
stty -ixon

I use it quite often, if I'm compiling something or during the boot process something catches my eye I hit ^S to stop, scroll up hoping that the message hasn't been pushed out the buffer, find the message and read it. ^Q to continue.

The thing I miss the most when it I sit down to someone elses machine is

PS1='$ '

.

The rest of my .bashrc is pretty basic:

if [ "$(hostname)" = "coppermine" ]; then
    alias ls='ls -G'
    EDITOR='/usr/local/bin/vim'
else
    alias ls='ls --color'
    EDITOR='/usr/bin/vim'
fi

alias ll='ls -lh'
alias u='whoami'
alias h='hostname'

MAIL="$HOME/Maildir/"
PS1='$ '

CLASSPATH='.'
for jar in ~/lib/*.jar; do
    CLASSPATH="$CLASSPATH:$jar"
done

export PS1 MAIL EDITOR CLASSPATH

Offline

#30 2006-06-07 13:08:51

palandir
Member
Registered: 2006-05-14
Posts: 73

Re: basic ~/.bashrc ~/.bash_profile tips thread

phildg wrote:
palandir wrote:
# Disable ^S/^Q flow control (does anyone like/use this at all?)
stty -ixon

I use it quite often, if I'm compiling something or during the boot process something catches my eye I hit ^S to stop, scroll up hoping that the message hasn't been pushed out the buffer, find the message and read it. ^Q to continue.

That's a point, but as for the boot messages, you can always scroll backwards or check the logs/dmesg, and as for the terminals, you can simply increase the buffer size... set it to 2000-3000 lines, that should be enough for everything. Or just redirect the output into a file (using "make | tee make.log" for example).

In any case, I find accidently hitting ^S more annoying, because it can happen quite often if you use keyboard shortcuts a lot. And if you didn't notice that you accidently hit it in some terminal, it's even worse.

Offline

#31 2006-08-22 05:59:32

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

rezza, some nice stuff wink

Hope no one minds me resurrecting this thread from the boneyard big_smile  I'll post some of my .bashrc file

#ALIAS'S OF ALL TYPES SHAPES AND FORMS ;)
#######################################################

# Alias's to local workstations
alias tom='ssh 192.168.2.102 -l root'
alias jason='ssh 192.168.2.103 -l root'
alias randy='ssh 192.168.2.104 -l root'
alias bob='ssh 192.168.2.105 -l root'
alias don='ssh 192.168.2.106 -l root'
alias counter='ssh 192.168.2.107 -l root'

# ALIAS TO REMOTE SERVERS
alias ANYNAMEHERE='ssh YOURWEBSITE.com -l USERNAME -p PORTNUMBERHERE'
# My server info removed from above for obvious reasons ;)

# Alias's to TN5250 programs. AS400 access commands.
alias d1='xt5250 env.TERM = IBM-3477-FC env.DEVNAME=D1 192.168.2.5 &'
alias d2='xt5250 env.TERM = IBM-3477-FC env.DEVNAME=D2 192.168.2.5 &'
alias tn5250j='nohup java -jar /home/crouse/tn5250j/lib/tn5250j.jar
2>>error.log &'

# Alias's to some of my BashScripts
alias bics='sh /home/crouse/scripts/bics/bics.sh'
alias backup='sh /home/crouse/scripts/usalugbackup.sh'
alias calc='sh /home/crouse/scripts/bashcalc.sh'
alias makepdf='sh /home/crouse/scripts/makepdf.sh'
alias phonebook='sh /home/crouse/scripts/PHONEBOOK/baps.sh'
alias pb='sh /home/crouse/scripts/PHONEBOOK/baps.sh'
alias ppe='/home/crouse/scripts/passphraseencryption.sh'
alias scripts='cd /home/crouse/scripts'

# Alias's to control hardware
alias cdo='eject /dev/cdrecorder'
alias cdc='eject -t /dev/cdrecorder'
alias dvdo='eject /dev/dvd'
alias dvdc='eject -t /dev/dvd'
alias scan='scanimage -L'
alias playw='for i in *.wav; do play $i; done'
alias playo='for i in *.ogg; do play $i; done'
alias playm='for i in *.mp3; do play $i; done'
alias copydisk='dd if=/dev/dvd of=/dev/cdrecorder' # Copies bit by bit
from dvd to cdrecorder drives.
alias dvdrip='vobcopy -i /dev/dvd/ -o ~/DVDs/ -l'

# Alias's to modified commands
alias ps='ps auxf'
alias home='cd ~'
alias pg='ps aux | grep'  #requires an argument
alias un='tar -zxvf'
alias mountedinfo='df -hT'
alias ping='ping -c 10'
alias openports='netstat -nape --inet'
alias ns='netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut
-c-6,21-94 | tail +2'
alias du1='du -h --max-depth=1'
alias da='date "+%Y-%m-%d %A    %T %Z"'
alias ebrc='pico ~/.bashrc'

# Alias to multiple ls commands
alias la='ls -Al'               # show hidden files
alias ls='ls -aF --color=always' # add colors and file type extensions
alias lx='ls -lXB'              # sort by extension
alias lk='ls -lSr'              # sort by size
alias lc='ls -lcr'      # sort by change time
alias lu='ls -lur'      # sort by access time
alias lr='ls -lR'               # recursive ls
alias lt='ls -ltr'              # sort by date
alias lm='ls -al |more'         # pipe through 'more'

# Alias chmod commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'

# Alias Shortcuts to graphical programs.
alias kwrite='kwrite 2>/dev/null &'
alias firefox='firefox 2>/dev/null &'
alias gaim='gaim 2>/dev/null &'
alias kate='kate 2>/dev/null &'
alias suk='kdesu konqueror 2>/dev/null &'

# Alias xterm and aterm
alias term='xterm -bg AntiqueWhite -fg Black &'
alias termb='xterm -bg AntiqueWhite -fg NavyBlue &'
alias termg='xterm -bg AntiqueWhite -fg OliveDrab &'
alias termr='xterm -bg AntiqueWhite -fg DarkRed &'
alias aterm='aterm -ls -fg gray -bg black'
alias xtop='xterm -fn 6x13 -bg LightSlateGray -fg black -e top &'
alias xsu='xterm -fn 7x14 -bg DarkOrange4 -fg white -e su &'

# Alias for lynx web browser
alias bbc='lynx -term=vt100 http://news.bbc.co.uk/text_only.stm'
alias nytimes='lynx -term=vt100 http://nytimes.com'

Offline

#32 2006-08-22 06:59:36

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: basic ~/.bashrc ~/.bash_profile tips thread

crouse wrote:
alias home='cd ~'

I use just: $ cd
to get home

thanks crouse, the ns alias is nice smile

Offline

#33 2006-08-22 09:57:44

kasparhouser
Member
Registered: 2003-03-28
Posts: 13

Re: basic ~/.bashrc ~/.bash_profile tips thread

crouse wrote:
alias dvdo='eject /dev/dvd'
alias dvdc='eject -t /dev/dvd'

eject -T does this in 1 line  wink

Offline

#34 2006-08-22 15:33:56

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

hmmmmmm that's a new option for the eject command, it didn't used to be there wink  In fact, on my suse 10.1 system, it's not an option.  However, on the arch system it is. Interesting.

dvdo = dvd open
dvdc = dvd close

was easy for me to remember that way wink  I can be a bit forgetful ..... so i HAD to make it easy lol.

Offline

#35 2006-08-22 16:18:49

jaboua
Member
Registered: 2005-11-05
Posts: 634

Re: basic ~/.bashrc ~/.bash_profile tips thread

Ooh nice post!

And I like your way of handling colors, much cleaner than this (my prompt):

PS1='ne[0;1m[e[35;1mWe[0;1m]:e[0m '

Offline

#36 2006-08-22 16:21:06

bboozzoo
Member
From: Poland
Registered: 2006-08-01
Posts: 125

Re: basic ~/.bashrc ~/.bash_profile tips thread

I use ksh most of the time

set -o emacs
set -o ignoreeof
alias  ee="exit"
stty intr ^C
stty kill ^X
stty erase ^X
stty -ixon
alias la='ls -a'
alias ll='ls -l'
alias lla='ls -al'

Offline

#37 2006-08-22 17:11:40

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

I'm pretty lazy too..... so I HATE having to type "pwd" to know where i am wink

export PS1="[[33[1;34mw[33[0m]n[t u]$ "
[~]
[12:19:04 crouse]$ cd scripts
[~/scripts]
[12:19:11 crouse]$ cd bbips
[~/scripts/bbips]
[12:19:15 crouse]$ cd bbipscommandline
[~/scripts/bbips/bbipscommandline]
[12:19:18 crouse]$

Some other interesting stuff.... exports ... ok, maybe not to everyone else...but to me wink

export EDITOR=/usr/bin/vi
export HISTFILESIZE=3000 # the bash history should save 3000 commands
export HISTCONTROL=ignoredups #don't put duplicate lines in the history.
alias hist='history | grep $1' #Requires one input

Offline

#38 2006-08-22 17:28:21

jerem
Member
From: France
Registered: 2005-01-15
Posts: 310

Re: basic ~/.bashrc ~/.bash_profile tips thread

I'm a laptop user and I like to use the following :

function bat1()
{
    echo $(( $(awk ' /remaining/ {print $3} ' /proc/acpi/battery/BAT0/state) * 100 / 71590 ))
}


function bat2()
{
    echo $(( $(awk ' /remaining/ {print $3} ' /proc/acpi/battery/BAT1/state) * 100 / 46620 ))
}


PS1="$(bat1)/$(bat2) u@h W $ "

# ALIAS

alias ls='ls --color=always --classify'
alias ll='ls --color=always --classify -alh | less'
alias pingg='ping -c 4 www.google.fr'
alias pingr='ping -c 4 192.168.1.1'
alias lss="ls -Ssh --color=always --classify"
alias la='ls -a --color=always --classify'

Prompt looks like that :

75/50 john@darkstar.net / $

It show the batteries %life remaining.

The functions may look somewhat weird but nesting things like that is faster than any other method I tried (using times command).

And giving the total capacity as a direct value avoids looking for it in /proc.

If you find a function that is faster than mine, I would be glad to test it.

Offline

#39 2006-08-22 17:32:16

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

Komodo wrote:
palandir wrote:

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 wink

I kind of like mmv

NAME
       mmv - move/copy/append/link multiple files by wildcard patterns

SYNOPSIS
       mmv [-m|x|r|c|o|a|l|s] [-h] [-d|p] [-g|t] [-v|n] [from to]

DESCRIPTION
       Mmv moves (or copies, appends, or links, as specified) each source file matching a from pattern to the target name specified by
       the to pattern.  This multiple action is performed safely, i.e. without any unexpected deletion of files due to  collisions  of
       target  names  with  existing filenames or with other target names.  Furthermore, before doing anything, mmv attempts to detect
       any errors that would result from the entire set of actions specified and gives the user the choice  of  either  proceeding  by
       avoiding the offending parts or aborting.

Offline

#40 2006-08-23 21:56:10

fk
Member
From: Germany
Registered: 2006-04-29
Posts: 524

Re: basic ~/.bashrc ~/.bash_profile tips thread

What a nice thread smile

So I have any Questions:

Why exists .bashrc and .bash_profile, when I only need one?

I will symlink .bashrc to .bash_profile, can I do this or must I attend anything?


These extract funbction is very cool 8), but how can I use the function?

I have try extract foo.tar, but extract is not found

# Functions
extract () {
   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   ;;
         *)         echo "'$1' cannot be extracted via extract()" ;;
      esac
   else
      echo "'$1' is not a valid file"
   fi
} 

Have you tried to turn it off and on again?

Offline

#41 2006-08-23 21:59:53

jaboua
Member
Registered: 2005-11-05
Posts: 634

Re: basic ~/.bashrc ~/.bash_profile tips thread

fk wrote:

Why exists .bashrc and .bash_profile, when I only need one?

I think one of them is run only when logging in, while the other one is run every time bash is run.

Offline

#42 2006-08-23 22:02:17

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

fk wrote:

These extract funbction is very cool 8), but how can I use the function?

I have try extract foo.tar, but extract is not found

Make sure that you either source your <code>.bashrc</code> or log out and log back on before trying to use the functions.  Just adding them to your file won't work until it gets read once again:

$ source ~/.bashrc

Offline

#43 2006-08-23 22:05:34

fk
Member
From: Germany
Registered: 2006-04-29
Posts: 524

Re: basic ~/.bashrc ~/.bash_profile tips thread

source ~/.bashrc

yehaa, it works..

I only have do

source /etc/profile

..


Have you tried to turn it off and on again?

Offline

#44 2006-08-24 03:29:37

McQueen
Member
From: Arizona
Registered: 2006-03-20
Posts: 387

Re: basic ~/.bashrc ~/.bash_profile tips thread

fk wrote:

I have try extract foo.tar, but extract is not found

- Did you logout/in?
- Did you run command as user?


/path/to/Truth

Offline

#45 2006-08-24 06:56:02

palandir
Member
Registered: 2006-05-14
Posts: 73

Re: basic ~/.bashrc ~/.bash_profile tips thread

Read "man bash", section "INVOCATION" for information which files bash automatically sources.

Offline

#46 2006-08-24 08:07:14

postlogic
Member
Registered: 2005-02-24
Posts: 410
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

@fk: Add it to your .bashrc and log out and in, or source .bashrc.

Offline

#47 2006-09-01 14:14:55

Elias
Member
From: Lyon (Fr)
Registered: 2006-01-19
Posts: 35
Website

Re: basic ~/.bashrc ~/.bash_profile tips thread

like ls -l but display file permissions in octal

BTW, i got a directory here that state : "drwxr-xr-t", what does it means and what is the octal value, if it exist, for that ?

lsoct () {
 ls -l | grep -v "total" | awk '{              
 owner=convert(substr($1,2,3))
 group=convert(substr($1,5,3))
 other=convert(substr($1,8,3) )
 $1 = owner group other " "
 print $1 $3":"$4 "  "$8
 }
 function convert(value)
 {
     if (value == "rwx")
        return "7"
     else if (value == "rw-")
        return "6"
     else if (value == "r-x")
        return "5"
     else if (value == "r--")
        return "4"
     else if (value == "-wx")
        return "3"
     else if (value == "-w-")
        return "2"
     else if (value == "--x")
        return "1"
     else if (value == "---")
        return "0"
     else
         return "_"
 }'
}

Offline

#48 2006-09-01 16:19:06

giddygiddyBA
Member
From: Montreal
Registered: 2004-12-30
Posts: 66

Re: basic ~/.bashrc ~/.bash_profile tips thread

Is there a way to write a function that does the opposite of this

extract()
{
    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   ;;  
            *)          echo "'$1' cannot be extracted" ;;
        esac
    else
        echo "'$1' is not a file"
    fi  
}

ex:  create tar.bz2 SOME_FILES  would create  SOME_FILES.tar.bz2 

Ideally, It could even be extended to
create zip -n NAME -f FILE1 FILE2 ...  which would create NAME.zip containing FILE1 FILE2 ....

Offline

#49 2006-09-02 17:13:15

TomE
Member
Registered: 2005-08-06
Posts: 164

Re: basic ~/.bashrc ~/.bash_profile tips thread

I got fedup typing "sudo pacman -Syu" and "sudo pacman -S foo" so wrote a fuction do it for me

pacman(){
    case $1 in
        -ss)  shift && pacsarch $*                  ;;
        -a)   shift && sudo /usr/bin/pacman -A $*   ;;
        -u)   shift && sudo /usr/bin/pacman -U $*   ;;
        -s)   shift && sudo /usr/bin/pacman -S $*   ;;
        -sy)  shift && sudo /usr/bin/pacman -Sy $*  ;;
        -su)  shift && sudo /usr/bin/pacman -Su $*  ;;
        -syu) shift && sudo /usr/bin/pacman -Syu $* ;;
        -R)   shift && sudo /usr/bin/pacman -Rs $*  ;;
        -r)   shift && sudo /usr/bin/pacman -R $*   ;;
        -*)   /usr/bin/pacman $*                    ;;
    esac
}
giddygiddyBA wrote:

Is there a way to write a function that does the opposite of this

smush () {
    FILE=$1
    case $FILE in
        *.tar.bz2) shift && tar cjf $FILE $* ;;
        *.tar.gz) shift && tar czf $FILE $* ;;
        *.tgz) shift && tar czf $FILE $* ;;
        *.zip) shift && zip $FILE $* ;;
        *.rar) shift && rar $FILE $* ;;
    esac
}

usage: smush ~/foo.tar.bz2 ./foo ./bar
I've don't use zip or rar so have no idea if they will work, but you get the idea.

Offline

#50 2006-09-02 23:02:20

giddygiddyBA
Member
From: Montreal
Registered: 2004-12-30
Posts: 66

Re: basic ~/.bashrc ~/.bash_profile tips thread

Thanks TomE.

yur function works well

i was sick of doing all that typing so i made some alias to quicken things up

in my home directory i added
#For Updating
alias u='sudo pacman -Syu'
#Grap new file list, but dont download
alias nu='yes no | sudo pacman -Syu'
#install
alias i='sudo pacman -S'

and im my /etc i added
#Search for file from repositories
alias s='pacman -Ss'
#Search Installed packages
alias si='pacman -Qi | grep'
#Search Package Groups
alias sg='pacman -Sg'
#Search for Name of Depository
alias sn='pacman -Sl'
#Pull up info on an installed package
alias sd='pacman -Qi'

things are really easy now, 
if i need to install something, just
i $PROG
updates
u
Search the dependency of a program
sd $PROG
etc...

Offline

Board footer

Powered by FluxBB