| View previous topic :: View next topic |
| Author |
Message |
CypherPipe n00b

Joined: 21 Mar 2005 Posts: 8
|
Posted: Fri Dec 04, 2009 7:42 pm Post subject: |
|
|
| 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 |
|
 |
ceric35 Tux's lil' helper


Joined: 27 Aug 2006 Posts: 97
|
Posted: Fri Dec 04, 2009 9:11 pm Post subject: |
|
|
Bash, redefine cd : | Code: | cd() {
builtin cd $*
ls -l
} |
|
|
| Back to top |
|
 |
skellr l33t


Joined: 18 Jun 2005 Posts: 698 Location: The Village
|
Posted: Tue Apr 20, 2010 4:43 pm Post subject: |
|
|
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.
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=' '
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 |
|
 |
muhsinzubeir l33t


Joined: 29 Sep 2007 Posts: 913 Location: /home/muhsin
|
Posted: Thu Jun 17, 2010 9:51 pm Post subject: |
|
|
| 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...  _________________ ~x86
p5k-se
Intel Core 2 Duo
Nvidia GT200
http://www.zanbytes.com |
|
| Back to top |
|
 |
ocin Guru

Joined: 01 Jan 2006 Posts: 500
|
Posted: Mon Jun 21, 2010 10:16 pm Post subject: |
|
|
Using ZSH.
Set READNULLCMD to cat:
for using
instead of
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:
use:
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
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 |
|
 |
truc Advocate


Joined: 25 Jul 2005 Posts: 3078
|
Posted: Sun Jul 11, 2010 3:12 am Post subject: |
|
|
| ocin wrote: | Using ZSH.
Set READNULLCMD to 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:
use:
For me this is more comfortable/logical (also it's making "useless cat" useful again ) |
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:
then
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 |
|
 |
truc Advocate


Joined: 25 Jul 2005 Posts: 3078
|
Posted: Fri Sep 03, 2010 8:17 pm Post subject: |
|
|
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 |
|
 |
rldawson n00b


Joined: 20 May 2011 Posts: 15
|
Posted: Wed Jun 08, 2011 9:46 pm Post subject: |
|
|
Place your $HOME/bin in $PATH:
| Code: | | [ -d $HOME/bin ] && { PATH=$PATH:$HOME/bin;export PATH; } |
|
|
| Back to top |
|
 |
SlashBeast Moderator


Joined: 23 May 2006 Posts: 2540 Location: Zduńska Wola, Poland.
|
Posted: Thu Jun 09, 2011 7:51 am Post subject: |
|
|
$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 |
_________________ github |
|
| Back to top |
|
 |
rldawson n00b


Joined: 20 May 2011 Posts: 15
|
Posted: Thu Jun 09, 2011 2:06 pm Post subject: |
|
|
On my rigs I prefer to allow the system to have first call and then $HOME, but I like your code sample.  |
|
| Back to top |
|
 |
rldawson n00b


Joined: 20 May 2011 Posts: 15
|
Posted: Sun Jun 12, 2011 3:49 am Post subject: |
|
|
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 |
|
 |
Ormaaj Guru

Joined: 28 Jan 2008 Posts: 312
|
Posted: Sat Jul 09, 2011 4:45 pm Post subject: |
|
|
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 |
|
 |
katfish Tux's lil' helper

Joined: 14 Nov 2011 Posts: 84
|
Posted: Thu Jan 12, 2012 9:28 pm Post subject: my bash aliases |
|
|
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 |
|
 |
tomk Administrator


Joined: 23 Sep 2003 Posts: 6793 Location: Sat in front of my computer
|
|
| Back to top |
|
 |
mthode Tux's lil' helper

Joined: 21 Apr 2005 Posts: 79 Location: San Antonio, TX USA
|
Posted: Tue Jan 17, 2012 4:16 pm Post subject: |
|
|
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 |
|
 |
krizz n00b

Joined: 15 Sep 2004 Posts: 26
|
Posted: Wed Jan 18, 2012 12:28 pm Post subject: |
|
|
| mthode wrote: | I also have a couple of other random and obvious things.
|
You can just do..
..to go back to your home directory as well, no need for an alias I'd say. |
|
| Back to top |
|
 |
ppurka Advocate

Joined: 26 Dec 2004 Posts: 2782
|
Posted: Wed Jan 18, 2012 12:51 pm Post subject: |
|
|
| krizz wrote: | | mthode wrote: | I also have a couple of other random and obvious things.
|
You can just do..
..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.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 |
|
 |
|