You are not logged in.
stupid simple note taker.
note ()
{
#if file doesn't exist, create it
[ -f $HOME/.notes ] || touch $HOME/.notes
#no arguments, print file
if [ $# = 0 ]
then
cat $HOME/.notes
#clear file
elif [ $1 = -c ]
then
> $HOME/.notes
#add all arguments to file
else
echo "$@" >> $HOME/.notes
fi
}
Offline
In some other thread about cleaning up directory names I wrote a script that makes all files nicer (remove weird characters and caps etc)
I made a small rewrite using mv's --backup.
#! /bin/bash
for FILE in *; do
NEWFILE="$(echo $FILE | \
sed -e 'y#QWERTYUIOPASDFGHJKLZXCVBNM#qwertyuiopasdfghjklzxcvbnm#
s#[^_.a-z0-9]#_#g
s#__*#_#g
s#^_##')"
if [ x"$FILE" = x"$NEWFILE" ]; then
continue
fi
if [ -z $NEWFILE ]; then NEWFILE="_"; fi
mv --backup=t -v -- "$FILE" "$NEWFILE"
done
Offline
png to jpg script (uses quality 80, only keeps the smallest version (sometimes png can be smaller))
#! /bin/bash
for file in *.png; do
jname="$(basename "$file" .png)".jpg
convert "$file" -quality 80 "$jname"
if [ $(du "$file" | awk '{print $1}') -gt $(du "$jname" | awk '{print $1}') ]; then
rm "$file"
else
rm "$jname"
echo kept png for "$file"
fi
done
Offline
freq ()
{
cpufreq=`cat /proc/cpuinfo | grep 'cpu MHz'`
echo ${cpufreq:31}
}
Not sure if this is right ... may need cleaning up a bit...
Mr Green
Offline
cp with a progress bar!
#!/bin/sh
cp_p()
{
set -e
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)
printf "="
printf ">"
for (i=percent;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}
Offline
nice one codemac, however, it prints a line after a line if the window size is smaller than 108 ( I used putty). In a wider window it draws over and over the same line.
Offline
Mines nothing special but it may help others:
alias ls='ls --color=auto'
#PS1='[\u@\h \W]\$ '
#PS1="\[\e[36;1m\]\u\[\e[1;34m\]@\[\e[32;1m\]\H \W :$ \[\e[0m\]"
PS1="\[\e[36;1m\]\u\[\e[1;34m\]@\[\e[32;1m\]\H \[\e[36;1m\]\w\[\e[32;1m\] :$ \[\e[0m\]"
export EDITOR="nano"
xhost +local:root > /dev/null
alias vps='ssh drakx@vps.ixl2.org -p 8341'
psc() {
echo -e "$(pacman -Ss $@ | sed \
-e 's#core/.*#\\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' )"
}
# should set a dynamic gnome-terminal title
case $TERM in
(xterm*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
;;
esac
I've to work out how to get the above title prompt to change from u@h pwd when i start an application to include the application name the in the title also..
Offline
I use theese in my zsh
function mkcd() { mkdir "$1" && cd "$1"; }
function dec() { printf "%d\n" $1}
function hex() { printf "0x%08x\n" $1}
function mktar() { tar czf "${1%%/}.tar.gz" "${1%%/}/"; }
function rot13() { echo "$@" | tr a-zA-Z n-za-mN-ZA-M; }
function getip() { lynx -dump http://whatismyip.org/ }
function nopaste() { curl -F file=@$1 nopaste.com/a }
function x()
{
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.tar.Z) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.jar) unzip "$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
}
`nopaste <file>` will paste the contents of <file> and give you back a link, `nopaste -` takes input from stdin
Last edited by tch (2008-01-29 18:06:14)
Offline
nice one codemac, however, it prints a line after a line if the window size is smaller than 108 ( I used putty). In a wider window it draws over and over the same line.
Yea, I need to add a $WIDTH calculation to it.
Offline
A configure flag maker, something to run after "./configure --help"
while [ x$done != xy ]; do
echo ENABLE:
read enab
ENAB="$ENAB $enab"
echo DISABLE:
read disab
DISAB="$DISAB $disab"
echo WITH:
read with
WITH="$WITH $with"
echo WITHOUT:
read without
WITHOUT="$WITHOUT $without"
echo DONE?
read done
done
DISFLAG=$(for ent in $DISAB; do echo --disable-$ent; done | xargs echo)
ENFLAG=$(for ent in $ENAB; do echo --enable-$ent; done | xargs echo)
WITHFLAG=$(for ent in $WITH; do echo --with-$ent; done | xargs echo)
WITHOFLAG=$(for ent in $WITHOUT; do echo --without-$ent; done | xargs echo)
echo $ENFLAG $DISFLAG $WITHFLAG $WITHOFLAG
Offline
cp with a progress bar!
very cool! thanks codemac! I was looking for something similar : ))
-- archlinux 是一个极好的 linux。
Offline
I always forget, that I'm making me some tea, so ...
alias caj='sleep 3m && kdialog --error "Dej si caj" &'
Last edited by drag0nl0rd (2008-02-05 21:00:18)
Offline
I'm pretty anal about the names of my downloaded stuff, and have gotten very tired of writing "for name in *.avi; do new=`echo $name | sed (blablabla) ... mv $name $new", so:
# change a certain part of the name of all files of a given extension
# usage: chname reg1 reg2 extension arg4
# (this will operate on all *.extension files)
# where reg1 and reg2 are regexps which fit into 'sed "s/reg1/reg2/"'
# arg4 is optional. If arg4 is present we echo the mv string.
chname()
{
if [ $# -lt 4 ]; then
echo "Error: We need at least three arguments"
return -1
fi
files=`ls *.${3}`
for name in $files; do
new=`echo $name | sed "s/${1}/${2}/"`
if [ $# -gt 3 ]; then
echo mv $name $new
else
if [ "$name" != "$new" ]; then
mv $name $new
fi
fi
done
}
Beware that you have plenty of rope to hang yourself. Use the fourth argument until you're sure that what you're doing actually works.
Last edited by gunnihinn (2008-02-06 16:58:32)
Offline
If you can express the substitution with wildcards you may like mmv. It will give you a bit more power and take away some of that rope as well.
Offline
Modify urxvt behavior depending on whether xcompmgr is running (semi- vs. true transparency):
function urxvt_mod()
{
if [ -z $(pidof xcompmgr) ]; then
urxvt
else
urxvt -depth 32 -bg rgba:0000/0000/0000/bbbb -tint grey
fi
}
alias urxvt='urxvt_mod'
Offline
Because I like a simple prompt, but a color can make things more clear I've added a simple prompt-color-entry into my .bashrc:
if [ -e /arch32 ] ; then
PS1='\e[1;33m\][32]\e[m\][\u@\h \W]\$ '
else
PS1='[\u@\h \W]\$ '
fi
The if-statement adds an orange [32] if I'm using the 32bit chroot-environment. For that, I just make an empty file in /opt/arch32/ called arch32. In my 64bit environment, the file is located at /opt/arch32/arch32, but in the 32bit environment, the file is located at /arch32. Al this is needed because both the 64bit and 32bit environments are using the same /home folder .
Because one can f*ck-up the whole system using the root-prompt, I've added soms red color when I'm logged in as root:
PS1='[\[\033[0;31m\]\u\[\033[0;39m\]@\h \W]\$ '
Because the 64bit and 32bit environments are not using the same /root directory, the above is placed into /root/.bashrc and the entry below is entered into /opt/arch32/root/.bachrc.
PS1='\e[1;33m\][32]\e[m\][\[\033[0;31m\]\u\[\033[0;39m\]@\h \W]\$ '
Hope somebody can use it .
Offline
~/.bashrc
alias ls='ls --color=auto'
PROMPT_COMMAND="source /etc/profile.d/color-prompt.inc"
/etc/profile.d/color-prompt.inc
## -*-shell-script-*-
## FILE /etc/profile.d/color-prompt.inc
#
# implement a function that will randomly colorize
# individual characters in a bash prompt
#
## COPYING
#
# color-prompt is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# color-prompt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# color-prompt. If not, see <http://www.gnu.org/licenses/>.
#
## END COPYING
## INCLUDED FILES
#
#
## END INCLUDED FILES
## MAIN color-prompt
#
# randomly colorize individual characters in a bash prompt
#
#printf "debug: entering color_prompt.inc\n"
index=$(( ${#USER} - 1 ))
colorized_name=""
brightness=
hue=
last_hue=
dir=
i="0"
while test "$i" -le "$index"; do
brightness=$RANDOM
let "brightness %= 2"
hue="0"
# shuffle colours..don't repeat and don't pick black
while test "$hue" -eq "0" || \
test "$hue" = "$last_hue"; do
hue=$RANDOM
let "hue %= 8"
done
this_color="\[\e[${brightness};3${hue}m\]"
last_hue="$hue"
if test -z "$colorized_name"; then
colorized_name="${this_color}${USER:${i}:1}"
else
colorized_name="${colorized_name}${this_color}${USER:${i}:1}"
fi
i="$(( $i + 1 ))"
done
tput sgr0
if test "$PWD" = "/home/${USER}"; then
dir="~"
else
dir=$(basename "$PWD")
fi
export PS1="[${colorized_name}\[$(tput sgr0)\]@${HOSTNAME} ${dir}]$ "
unset index colorized_name brightness hue last_hue dir i
#
#
#
## END OF FILE /etc/profile.d/color-prompt.inc
Offline
I always forget, that I'm making me some tea, so ...
alias caj='sleep 3m && kdialog --error "Dej si caj" &'
What sort of tea is that? You must have forgotten the 1 before the 3 Oh, and seeing the use of kdialog, you are aware of kteatime I suppose.
never trust a toad...
::Grateful ArchDonor::
::Grateful Wikipedia Donor::
Offline
Since I am a lazy typer, I am customed to this set of shortcut aliases for some years now.
alias ls='ls --color=auto'
alias l='ls'
alias la='ls -a'
alias ll='ls -l'
alias lla='ls -la'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../../'
# Remove with caution but do not annoy me.
alias rm='rm -I'
# All-purpose edit commands
# GUI only
alias Edit='gvim'
alias edit='xterm -e vim'
# Non-GUI only
#alias Edit='vim'
#alias edit='vim -u /home/bp/.vimrc-nogui'
#alias screen='screen -Ua'
# Some startup and shutdown conveniences
alias _X='startx'
alias _G='xinit /usr/bin/gnome-session'
alias _K='xinit /usr/bin/startkde'
# Easier shutdown from inside IceWM 1.2.x
alias _YY='sudo shutdown -r now'
alias _ZZ='sudo shutdown -h now'
# Other aliases
alias PM='yaourt'
Additionally some UI conveniences.
# Use colored display in man pages.
# (Requires "DEFINE pager less -Rs" in /etc/man_db.conf)
# These stand out better on a white background Xterm.
# - blinking on: magenta
export LESS_TERMCAP_mb=$'\E[35m'
# - bold on: red
export LESS_TERMCAP_md=$'\E[31m'
# - all attributes off
export LESS_TERMCAP_me=$'\E[0m'
# - exit standout mode
export LESS_TERMCAP_se=$'\E[0m'
# - begin standout mode (e.g. status line): bold yellow on blue
export LESS_TERMCAP_so=$'\E[01;44;33m'
# - exit underline mode
export LESS_TERMCAP_ue=$'\E[0m'
# - begin underline mode: blue
export LESS_TERMCAP_us=$'\E[34m'
# Use colored prompts:
#
# - With terminal indicator
#PS1="\[\e[0;35m\]\l-\u:\[\e[0;34m\]\w\[\e[0;35m\]\$\[\e[0;0m\] "
# - Without terminal indicator
PS1="\[\e[0;35m\]\u:\[\e[0;34m\]\w\[\e[0;35m\]\$\[\e[0;0m\] "
#
PS2="\[\e[0;35m\]>\[\e[0;0m\] "
PS3="\[\e[0;35m\]-\[\e[0;0m\] "
PS4="\[\e[0;35m\]+\[\e[0;0m\] "
# Make sure less leaves the XTerm screen uncleared
export LESS="-MX"
# History
# Do not automatically execute ! commands.
shopt -s histverify
Root .bashrc complements those PS1 et.al. prompts with their own color definitions. Thus user/root terminals remain easily distinguishable. (I often have half a dozen Xterms open here.)
To know or not to know ...
... the questions remain forever.
Offline
Just some handy keybindings I use:
# M-C-y: prefix commandline with 'yes | ' and run it
bind '"\e\C-y":"\C-ayes | \C-e\n"'
# M-s: wrap commandline in su -c '' and run it
bind '"\es":"\C-asu -c \x27\C-e\x27\C-m"'
# M-C-l: append ' | less' to commandline and run it
bind '"\e\C-l":"\C-e | less\C-m"'
Offline
zsh users might want to look into the grml keephack. It's incredibly useful, especially if you are unable to use a pipeline for some reason.
Offline
# Check for an interactive session
[ -z "$PS1" ] && return
alias pac='sudo pacman-color'
alias ls='ls --color=auto'
alias cd..='cd ..'
eval `dircolors -b`
PS1='\[\e[1;33m\]┌─[\[\e[1;37m\]\u @ \t @ \d\[\e[1;33m\]] \n└─[\[\e[1;37m\]\W\[\e[1;33m\]]\[\e[1;37m\]>> \[\e[1;33m\]'
PS2='>'
cd() {
if [ -n "$1" ]; then
builtin cd "$@" && ls
else
builtin cd ~ && ls
fi
}
export GREP_COLOR="1;33"
alias grep='grep --color=auto'
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
./archinfo.pl
nice change directory function
Last edited by na12 (2009-03-06 20:40:22)
Offline
Nice thread!
Offline
Someone should write a quick little "define" function that look at urban dictionary and returns the results as such.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Online
Someone should write a quick little "define" function that look at urban dictionary and returns the results as such.
This is quite crude but works - someone can tidy it up for me:
#!/bin/sh
#
#simple script to get Urban Dictionary one word definition to the terminal
#Usage: scriptname word
#
wget -q -O - www.urbandictionary.com/define.php?term=$1 | grep definition | sed -e 's#<[^>]*>##g' | sed -e 's/"//g'
Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.
Offline