Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Console / shell tips & tricks
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3 ... 13, 14, 15  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
CypherPipe
n00b
n00b


Joined: 21 Mar 2005
Posts: 8

PostPosted: Fri Dec 04, 2009 7:42 pm    Post subject: Reply with quote

Code:
function ta ()
# `type -a` with more info about what "/path/file" is.
# $ ta {,z,lz}cat
# cat is /bin/cat : ELF 32-bit LSB executable
# zcat is /bin/zcat : POSIX shell script text executable
# lzcat is /usr/bin/lzcat : symbolic link to `lzma'
{
    local IFS=$'\x0A' # \n
    regex=$(eval echo -e '\(/[[:graph:]]*\)[^\\x3b\\x27\\x22]$')
#                                               ;    '    "
    for line in $(type -a "$@");
    do
        if [[ $line =~ $regex ]]; then
            tmi=$(file $BASH_REMATCH);
            trimed=${tmi%%,*};
            echo ${line%%/*}${trimed/:/ :};
        else
            echo $line;
        fi;
    done
}
Back to top
View user's profile Send private message
ceric35
Tux's lil' helper
Tux's lil' helper


Joined: 27 Aug 2006
Posts: 103

PostPosted: Fri Dec 04, 2009 9:11 pm    Post subject: Reply with quote

Bash, redefine cd :
Code:
cd() {
  builtin cd $*
  ls -l
}
Back to top
View user's profile Send private message
skellr
l33t
l33t


Joined: 18 Jun 2005
Posts: 706
Location: The Village

PostPosted: Tue Apr 20, 2010 4:43 pm    Post subject: Reply with quote

I was looking for a thread titled "post your stupid scripts", or something to that effect, but can't seem to find it. Maybe this one will work. :wink:
I wanted something to help choose a foreground color against a chosen background color.
Code:
#!/bin/bash
if ! { data=$(showrgb); } &> /dev/null
then for x in                        \
   /etc/X11/rgb.txt             \
   /usr/lib/X11/rgb.txt         \
   /usr/share/X11/rgb.txt       \
   /usr/X11R6/lib/X11/rgb.txt   \
   /usr/openwin/lib/X11/rgb.txt \
   /usr/share/doc/python*/examples/Tools/pynche/X/rgb.txt
do
    if [[ -r $x ]]; then
   data=$(sed '/^!/d' < $x)
   break
    fi
done
fi

[[ -z "$data" ]] && { echo "Can't find \`showrgb\` or rgb.txt"; exit; }

while getopts "hub: c: f: o:" option
do
    case "$option" in
   b|c) bgcolor=$OPTARG;;
   o|f) exec > $OPTARG;;
   \?|h|u) cat <<-Hdoc
   Usage: ${0##*/} [-b color] [-o file] || ${0##*/} [-c color] [-f file]
          -b or -c   Specify a background color.
             -b \#000 | -b \#000000 | -b black | -b 'rgb(0,0,0)'
          -o or -f   Write output to file.
      Hdoc
       exit 1;;
    esac
done

declare -i r g b
sample="The quick brown fox jumps over the lazy dogs back."
fill='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'

cat <<Hdoc
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.1 Strict//EN">
<html>
 <head>
  <title>rgb.txt Colors</title>
  <style type="text/css">
   body { background-color: ${bgcolor:-none} }
   ul   { list-style-type: none; padding-left: 1% }
   span { border: thin inset }
   pre  { display: inline }
  </style>
 </head>
 <body>
  <ul>
Hdoc

while read r g b name
do
    printf -v hex "\x23%02x%02x%02x" $r $g $b
    printf '   <li style="color: %s">\n' $hex
    printf '    <span style="background-color: %s">%s</span>\n' $hex $fill
    printf '    <pre> %s  %-23s</pre>%s\n' $hex "$name" "$sample"
    printf '   </li>\n'
done <<< "$data"

cat <<Hdoc
  </ul>
 </body>
</html>
Hdoc


edit: output is html
Back to top
View user's profile Send private message
muhsinzubeir
l33t
l33t


Joined: 29 Sep 2007
Posts: 938
Location: /home/muhsin

PostPosted: Thu Jun 17, 2010 9:51 pm    Post subject: Reply with quote

Code:
#dvd to flv
alias dvd-to-flv='mplayer dvd://1 -dumpstream -dumpfile video.vob && ffmpeg -i video.vob -vcodec flv -b 1024kb -acodec libmp3lame -ar 22050 -pass 1 -f flv video.flv && ffmpeg -i video.vob -vcodec flv -b 1024kb -acodec libmp3lame -ar 22050 -pass 2 -f flv video.flv'

#avi to flv
alias avi-to-flv='ffmpeg -i video.avi -ar 44100 -ab 64k -b 400k -f flv -s 320x240 video.flv'

#wav to mp3
alias wav-to-mp3='ffmpeg -i filename.wav -acodec libmp3lame -ab 160k -ac 2 -ar 44100 filename.mp3'

Finally... :P
_________________
~x86
p5k-se
Intel Core 2 Duo
Nvidia GT200
http://www.zanbytes.com
Back to top
View user's profile Send private message
ocin
Guru
Guru


Joined: 01 Jan 2006
Posts: 500

PostPosted: Mon Jun 21, 2010 10:16 pm    Post subject: Reply with quote

Using ZSH.

Set READNULLCMD to cat:
Code:
READNULLCMD="cat"

for using
Code:
$ < file

instead of
Code:
$ cat file

which is quite cool with aliases like
Code:

alias -g G='|grep'
alias -g H='|head'
alias -g L='|less'
alias -g M='|more'
alias -g N='&>/dev/null'
alias -g P='|curl -F "sprunge=<-" http://sprunge.us'
alias -g S='|sort'
alias -g T='|tail'
alias -g W='|wc -l'
alias -g X='|xargs'


Examples:

This will cat file, grep for string and nopaste the result at sprunge:
Code:
$ < file G string P


Or instead of doing:
Code:
$ grep string file

use:
Code:
$ < file G string

For me this is more comfortable/logical (also it's making "useless cat" useful again :D)


Auto-attach screen when connecting to a remote linux server, for example useful if you run a screened irssi on it or just wanna auto-attach your working screen:
Code:

if [[ $HOST = "yourhostname" ]]; then
   [[ ! -z $(screen -list | grep nameofscreen | grep Detached) ]] && screen -aADRS nameofscreen
fi


Completion for a specific command:
Code:
compctl -g '*.ebuild' ebuild
compctl -g '*.torrent' hrktorrent

For example you type
Code:
$ hrktorrent <TAB>

and it will only list all files ending with .torrent and folders of course


TAB/Arrow-Key driven kill menu:
Code:
zstyle ':completion:*:kill:*' force-list always
zstyle ':completion:*:processes' insert-ids
if [[ $UID = "0" ]]; then
        zstyle ':completion:*:processes' command 'ps axf -o pid,%cpu,%mem,tty,cputime,cmd | sed /ps/d | grep -vE "sed|grep"'
else
        zstyle ':completion:*:processes' command 'ps f -u $USER -o pid,%cpu,%mem,tty,cputime,cmd | sed /ps/d | grep -vE "sed|grep"'
fi
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'



Strip comments and blank lines out of a file:
Code:
alias confcat='grep -vE "^#|^$"'



Easy scp (in this example "foo" is a hostname configured in ~/.ssh/config)
Code:
cp2web() { scp $* foo:public_html }



Check for window properties, useful with windows managers where you need them or tools like devilspie:
Code:
propstrings() { xprop | grep -E '^(WM_NAME)|(WM_WINDOW_ROLE)|(WM_CLASS)' }



Easy ssh unkey:
Code:
unkey_host() {
   if [[ ! $# -eq 1 ]]; then
      echo "usage: unkey_host <hostname>"
   else
      sed -i -e "/$1/d" $HOME/.ssh/known_hosts
   fi
}



Finally my gentoo specific aliases:
Code:
if [[ $HOST = "hostname" && $UID = "0" ]]; then
   alias kmake='make -j3 && make install && make modules_install'
   alias python-updater='python-updater -P paludis'
   alias srcenv='env-update && source /etc/zsh/zprofile && source ~/.zshrc'
   alias uninstall-unused='paludis --uninstall-unused && reconcilio'
   alias vipk='vim /etc/paludis/keywords.conf'
   alias vipo='vim /etc/paludis/use.conf'
   alias vipu='vim /etc/paludis/package_unmask.conf'
   alias vipm='vim /etc/paludis/package_mask.conf'
   alias vipb='vim /etc/paludis/bashrc'
fi
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Sun Jul 11, 2010 3:12 am    Post subject: Reply with quote

ocin wrote:
Using ZSH.

Set READNULLCMD to cat:
Code:
READNULLCMD="cat"

[...]
which is quite cool with aliases like
Code:

alias -g G='|grep'
alias -g H='|head'
alias -g L='|less'
alias -g M='|more'
alias -g N='&>/dev/null'
alias -g P='|curl -F "sprunge=<-" http://sprunge.us'
alias -g S='|sort'
alias -g T='|tail'
alias -g W='|wc -l'
alias -g X='|xargs'


Examples:

This will cat file, grep for string and nopaste the result at sprunge:
Code:
$ < file G string P


Or instead of doing:
Code:
$ grep string file

use:
Code:
$ < file G string

For me this is more comfortable/logical (also it's making "useless cat" useful again :D)


I don't really know zsh, but I'm 99% sure you don't need to set READNULLCMD=cat to use do that, "<file" is just the same as telling stdin = read from "file" and grep, as well as other, can use standard input, and that's even what's happening the way you're calling it (cat file | grep blah).

I still see a useless cat here;)

Try this:
Code:
alias G=grep

then
Code:
<file G blah



And btw, since I like 'ed' here is my delKnownHost function
declare -f delKnownHost:
delKnownHost ()
{
    [ -z "$1" ] && {
        echo "delKnownHost number";
        return 1
    };
    ed -s ~/.ssh/known_hosts  <<EOT
H
${1}d
wq
EOT

}

_________________
The End of the Internet!
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Fri Sep 03, 2010 8:17 pm    Post subject: Reply with quote

whereas you're a tmux user or a screen one, it's so easy to start a new shell in a split window(well it's easier with tmux..) just to check a few things that I tend to do it like all the time... One thing which used to annoy me when doing this is the time spent loading bash completion.

Since I usually don't need it for the few first commands I run in this split window, I decided I could delay a little this loading.
By delaying it a little I mean, not loading it before the first prompt, but later, I chose to load them after the third command.

If you're also that impatient, add this to your .bashrc
Code:
# sourcing /etc/bash_completion takes some time, try to delay it a little
_MYCMDNB=0
my_prompt_command() {
   _MYCMDNB=$((_MYCMDNB+1))
   if [ $_MYCMDNB -gt 3 ]; then
      [ -f /etc/bash_completion ] && source /etc/bash_completion
      unset PROMPT_COMMAND
      unset _MYCMDNB
      unset my_prompt_command
   fi
}
PROMPT_COMMAND=my_prompt_command


Of course, you'll have to adapt it if you already use the PROMPT_COMMAND for something.
_________________
The End of the Internet!
Back to top
View user's profile Send private message
rldawson
n00b
n00b


Joined: 20 May 2011
Posts: 19

PostPosted: Wed Jun 08, 2011 9:46 pm    Post subject: Reply with quote

Place your $HOME/bin in $PATH:

Code:
[ -d $HOME/bin ] && { PATH=$PATH:$HOME/bin;export PATH; }
Back to top
View user's profile Send private message
SlashBeast
Moderator
Moderator


Joined: 23 May 2006
Posts: 2837

PostPosted: Thu Jun 09, 2011 7:51 am    Post subject: Reply with quote

$HOME/bin should be first in PATH so it will be choosen over system's bin dirs.

from my zshrc
Code:
if ! [[ "${PATH}" =~ "^${HOME}/bin" ]]; then
        export PATH="${HOME}/bin:${PATH}"
fi

_________________
BitBucket -- better-initramfs
Back to top
View user's profile Send private message
rldawson
n00b
n00b


Joined: 20 May 2011
Posts: 19

PostPosted: Thu Jun 09, 2011 2:06 pm    Post subject: Reply with quote

On my rigs I prefer to allow the system to have first call and then $HOME, but I like your code sample. :D
Back to top
View user's profile Send private message
rldawson
n00b
n00b


Joined: 20 May 2011
Posts: 19

PostPosted: Sun Jun 12, 2011 3:49 am    Post subject: Reply with quote

alias this command to hash your directories:
Code:
sha=sha512sums-${PWD##*/};[ -f $sha ] && rm $sha;find . -type f -exec sha512sum {} \; > /tmp/$sha;mv /tmp/$sha .
Back to top
View user's profile Send private message
Ormaaj
Guru
Guru


Joined: 28 Jan 2008
Posts: 316

PostPosted: Sat Jul 09, 2011 4:45 pm    Post subject: Reply with quote

Print today's merges:

Bash (requires version >= 4.2):
Code:
f(){ [[ -n "${1%%"${1##"$2"}"}" ]] && echo "${1#*>>> }"; }; qlop -Cl | tail -n 1000 | while read -r; do f "$REPLY" "$(printf '%(%a %b %d)T' -1)"; done

Awk:
Code:
qlop -Cl | tail -n 1000 | gawk -F '>>>[[:space:]]*' '{split($0,a,/[[:space:]]+/)} strftime("%a %b %d",systime()) == a[1]" "a[2]" "a[3] {print $2}'
Back to top
View user's profile Send private message
katfish
Tux's lil' helper
Tux's lil' helper


Joined: 14 Nov 2011
Posts: 109

PostPosted: Thu Jan 12, 2012 9:28 pm    Post subject: my bash aliases Reply with quote

might be useful for you too...

alias c='clear'
alias ls='ls --color'
alias l='ls -lah --color'
alias df='df -h'
alias du='du -h'
alias ..='cd ..'
alias loc='locate'
alias k9='kill -9 '
alias psg='ps aux | grep '
alias e='emerge'
alias ew='e world -uDNv --keep-going'
alias es='layman -S;eix-sync'
alias ewa='e world -uDNtav --keep-going'
alias edc='e --depclean -av'
alias dpc='dispatch-conf'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

export HISTCONTROL=erasedups
export HISTSIZE=1000000
shopt -s histappend
shopt -s checkwinsize
Back to top
View user's profile Send private message
tomk
Administrator
Administrator


Joined: 23 Sep 2003
Posts: 7219
Location: Sat in front of my computer

PostPosted: Fri Jan 13, 2012 9:20 am    Post subject: Reply with quote

Merged previous post.
_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
prometheanfire
Developer
Developer


Joined: 21 Apr 2005
Posts: 87
Location: San Antonio, TX USA

PostPosted: Tue Jan 17, 2012 4:16 pm    Post subject: Reply with quote

my update vcs-sync script (to update all my repos and stuff and put me back where I started)

Code:
vcs-sync() {
   pushd /home/mthode/gentoo-x86
   cvs up
   echo "/home/mthode/hardened-dev"
   cd /home/mthode/hardened-dev
   git pull
   echo "/home/mthode/sunrise"
   cd /home/mthode/sunrise
   svn up
   echo "/home/mthode/prometheanfire"
   cd /home/mthode/prometheanfire
   git pull
   popd
}


I also have a couple of other random and obvious things.

Code:
alias           ~='cd ~'
alias           ..='cd ..'
alias           ...='cd ../..'
alias           ....='cd ../../..'
alias           .....='cd ../../../..'
alias           rm="rm -i"
alias      ls="ls -G"
alias           ssh="ssh -A -o VisualHostKey=yes"
alias           webshare='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'
alias           pgrep='pgrep -lf'
complete        -cf sudo

_________________
-- Matthew Thode (prometheanfire)
Back to top
View user's profile Send private message
krizz
n00b
n00b


Joined: 15 Sep 2004
Posts: 26

PostPosted: Wed Jan 18, 2012 12:28 pm    Post subject: Reply with quote

mthode wrote:
I also have a couple of other random and obvious things.

Code:
alias           ~='cd ~'


You can just do..

Code:
cd


..to go back to your home directory as well, no need for an alias I'd say.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3206

PostPosted: Wed Jan 18, 2012 12:51 pm    Post subject: Reply with quote

krizz wrote:
mthode wrote:
I also have a couple of other random and obvious things.

Code:
alias           ~='cd ~'


You can just do..

Code:
cd


..to go back to your home directory as well, no need for an alias I'd say.
In fact many of those bindings come for free with zsh.
Code:
setopt autocd
This will make .. work and take you to parent directory. Also ~ by itself will take you to home directory.

Also, I wonder why ..... etc are so "popular"? Why not an alias .3, .4 and .5 to go up 3, 4, or 5 directories respectively?
_________________
emerge --quiet redefined | E17 vids: I, II
Back to top
View user's profile Send private message
slick
Bodhisattva
Bodhisattva


Joined: 20 Apr 2003
Posts: 3487

PostPosted: Wed Jun 04, 2014 3:44 pm    Post subject: Reply with quote

Set the time via internet with bash only:

Code:
date -u '+%y-%m-%d %H:%M:%S' -s "$(cat </dev/tcp/time.nist.gov/13|cut -d ' ' -f2,3)"
Back to top
View user's profile Send private message
khayyam
Advocate
Advocate


Joined: 07 Jun 2012
Posts: 2246

PostPosted: Thu Jun 05, 2014 1:26 pm    Post subject: Reply with quote

ppurka wrote:
Also, I wonder why ..... etc are so "popular"? Why not an alias .3, .4 and .5 to go up 3, 4, or 5 directories respectively?

ppurka ... well, I use the former for 'cd' and the latter as 'global' ('-g') aliases just to denote the path, I also have alias 2=' cd +2', etc, which just adds to the smorgasbord of options :)

I do this as I'm lazy, mostly ... but also because I might use them in different ways.

Code:
# pwd
/home/khayyam/foo/ba/src
# mv foo .2 ; 2
# pwd
/home/khayyam/foo
# 1 ; pwd
/home/khayyam/foo/ba/src
# .. ; pwd
/home/khayyam/foo/ba

The '..' aliases I use mainly because its just a matter of hitting the period key a couple of times ... did I mention I'm lazy? :) I also use 'push/popd +|-' (which I have aliased to 'pu' and 'po') so ... various methods of achieving the same results.

best ... khay
Back to top
View user's profile Send private message
khayyam
Advocate
Advocate


Joined: 07 Jun 2012
Posts: 2246

PostPosted: Thu Jun 05, 2014 1:37 pm    Post subject: Reply with quote

SlashBeast wrote:
$HOME/bin should be first in PATH so it will be choosen over system's bin dirs.

from my zshrc
Code:
if ! [[ "${PATH}" =~ "^${HOME}/bin" ]]; then
        export PATH="${HOME}/bin:${PATH}"
fi

SlashBeast ... this isn't necessary with zsh as it has a 'path' array (lowercase) ... the array is cleared of any duplicates and used to provide $PATH. You can also use a 'glob qualifier' to ignore if the directory doesn't exist.

~/.zprofile
Code:
typeset -U path
export path
 
path=($HOME/bin(N-/) $path)

best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2, 3 ... 13, 14, 15
Page 15 of 15

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum