A very nice .vimrc file for any Linux user, this makes VI or VIM easier to use.
" ~/.vimrc (configuration file for vim only) " skeletons function! SKEL_spec() 0r /usr/share/vim/current/skeletons/skeleton.spec language time en_US if $USER != '' let login = $USER elseif $LOGNAME != '' let login = $LOGNAME else let login = 'unknown' endif let newline = stridx(login, "\n") if newline != -1 let login = strpart(login, 0, newline) endif if $HOSTNAME != '' let hostname = $HOSTNAME else let hostname = system('hostname -f') if v:shell_error let hostname = 'localhost' endif endif let newline = stridx(hostname, "\n") if newline != -1 let hostname = strpart(hostname, 0, newline) endif exe "%s/specRPM_CREATION_DATE/" . strftime("%a\ %b\ %d\ %Y") . "/ge" exe "%s/specRPM_CREATION_AUTHOR_MAIL/" . login . "@" . hostname . "/ge" exe "%s/specRPM_CREATION_NAME/" . expand("%:t:r") . "/ge" setf spec endfunction autocmd BufNewFile *.spec call SKEL_spec() " filetypes filetype plugin on filetype indent on " ~/.vimrc ends here set nu |
A nice bash function to find bad symlinks in a directory. Just run it and all bad symlinks will be found.
function badlink() # From Atomic magazine #43 August 2004. http://www.atomicmpc.com.au { DEFAULT=$(tput sgr0); FILELIST=.badlink.list [ -e $FILELIST ] && $( rm -fr $FILELIST ) function checklink() { for badlink in $1/*; do [ -h "$badlink" -a ! -e "$badlink" ] && echo \ \"$badlink\" >> $FILELIST [ -d "$badlink" ] && checklink $badlink done } for directory in `pwd`; do if [ -d $directory ] ; then checklink $directory; fi done if [ -e $FILELIST ] ; then for line in $(cat $FILELIST); do echo $line | xargs -r rm | echo -e "$line \ -removed" echo done rm -fr $FILELIST else printf "Bad symlinks not found.\n\n" fi } # End Atomic function. |
A bash function to move all filenames in a directory to lowercase. This is a very fast way to rename a lot of files in one go.
function lowercase() # move filenames to lowercase. { for file ; do filename=${file##*/} case "$filename" in */*) dirname==${file%/*} ;; *) dirname=.;; esac nf=$(echo $filename | tr A-Z a-z) newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then mv "$file" "$newname" echo "lowercase: $file --> $newname" else echo "lowercase: $file not changed." fi done } |
Here is a program I wrote to set a random wallpaper for a Linux desktop. Just type wmsetbg -s ~/Wallpapers/photohm/$(img)
to set a random wallpaper. Compile with gcc -Wall -Os photos.c -o img
. Very interesting program indeed.
/******************************************************************** * Description: Random image program. * Author: bejiitas * Created at: Tue Apr 17 02:08:47 EDT 2007 * Computer: opensuse * System: Linux 2.6.20.2-Lorien on i686 * * Copyright (c) 2007 bejiitas_wrath All rights reserved. * ********************************************************************/ /* * This is how I generated this list in the first place... * for file in *.jpg; do echo -ne "\"$file\"," >> ~/out.txt; done; */ #include "stdio.h" #include "stdlib.h" #include "time.h" const char* files[] = { "j0144216.jpg", "j0144217.jpg", "j0144226.jpg", "j0144227.jpg", "j0144228.jpg", "j0144232.jpg", "j0144233.jpg", "j0144234.jpg", "j0144235.jpg", "j0144236.jpg", "j0144237.jpg", "j0144243.jpg", "j0144247.jpg", "j0144248.jpg", "j0144269.jpg", "j0144281.jpg", "j0144282.jpg", "j0144287.jpg", "j0144288.jpg", "j0144291.jpg", "j0144294.jpg", "j0144295.jpg", "j0144296.jpg", "j0144297.jpg", "j0144300.jpg", "j0144301.jpg", "j0144302.jpg", "j0144304.jpg", "j0144305.jpg", "j0144306.jpg", "j0144308.jpg", "j0144309.jpg", "j0144310.jpg", "j0144311.jpg", "j0144312.jpg", "j0144314.jpg", "j0144318.jpg", "j0144324.jpg", "j0144325.jpg", "j0144326.jpg", "j0144329.jpg", "j0144333.jpg", "j0144337.jpg", "j0144338.jpg", "j0144340.jpg" }; const size_t urls = sizeof (files) / sizeof (*files) - 1; int RandLink() { int Num; srand ((unsigned)time(NULL)); Num = rand() % urls; return Num; } int main() { printf("%s", files[RandLink()]); return 0; } |
Here is a small Perl script that will list the contents of a directory branching off of the current directory. A very useful script. The output is sorted to make the output easier to read and to find what you are looking for. I wanted to use getc() but I decided using chomp() was easier.
#!/usr/bin/perl -W use strict; use warnings; printf("Please enter a directory to view.\n"); chomp( my $dir = <STDIN>); if (!$dir) { printf("You did not enter a directory!\n"); exit; } else { my $path = $ENV{"PWD"}; printf("\n%s\/%s\n", $path, $dir); opendir(DNAME, "$dir") || die "I cannot open that dir!\n $!"; { my @dir = readdir(DNAME); @dir = sort(@dir); foreach my $x (@dir) { print "$x\n"; } } } |
My very useful .zshrc file for Linux users.
# /etc/zsh-beta/zshrc: system-wide .zshrc file for zsh-beta(1). export MAIL=/var/spool/mail/$USERNAME export LESS=-cex3M export EDITOR=vim export HELPDIR=/usr/local/lib/zsh/help # directory for run-help function to find docs manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man) export WINDOWMANAGER=/usr/bin/wmaker manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man:/usr/share/man) # Adding /usr/share/man to the search path for Mepis GNU/Linux. export MANPATH # Misc colors. export NORMAL=" \e[0m" export GREEN=" \e[1;32m" export YELLOW=" \e[1;33m" export WHITE=" \e[1;37m" export CYAN=" \e[1;36m" MAILCHECK=300 HISTSIZE=200 DIRSTACKSIZE=20 eval `dircolors -b` # Use hard limits, except for a smaller stack and no core dumps unlimit limit stack 8192 limit core 0 limit -s umask 022 # Set up aliases alias mv='nocorrect mv' # no spelling correction on mv alias cp='nocorrect cp' # no spelling correction on cp alias mkdir='nocorrect mkdir' # no spelling correction on mkdir alias j=jobs alias pu=pushd alias po=popd alias d='dirs -v' alias h=history alias grep=egrep alias ll='ls -l' alias la='ls -a' alias cls='clear' alias lu='ls -hula' # More useful Aliases. alias tarunpack='tar -zxvf' alias bz2unpack='tar -jxvf' # List only directories and symbolic # links that point to directories alias lsd='ls -ld *(-/DN)' # List only file beginning with "." alias lsa='ls -ld .*' # This code courtesy of Emacs ;). # Not everyone has finger(1). if [ -x /usr/bin/finger ] ; then INFO=$(finger -lmps $LOGNAME | fgrep On ) alias userlist='finger -lmps' else INFO=$(uname -msov) alias userlist='users' fi # Shell functions setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" } # csh compatibility freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done } # These following functions from http://www.die.net/doc/linux/abs-guide/sample-bashrc.html function my_ip() # get IP adresses. Bracket on next line C style... { MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | sed -e s/addr://) MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P://) } function lowercase() # move filenames to lowercase. { for file ; do filename=${file##*/} case "$filename" in */*) dirname==${file%/*} ;; *) dirname=.;; esac nf=$(echo $filename | tr A-Z a-z) newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then mv "$file" "$newname" echo "lowercase: $file --> $newname" else echo "lowercase: $file not changed." fi done } # Where to look for autoloaded function definitions fpath=($fpath ~/.zfunc) READNULLCMD=${PAGER:-/usr/bin/pager} echo -e "${CYAN}" if [ -x /usr/games/fortune ] ; then echo fortune -l echo else echo -e "Fortune not found." fi echo -e "${NORMAL}" echo -e "${YELLOW}" echo -e "${INFO}" echo -e "$NORMAL" autoload -U compinit compinit autoload -U promptinit; promptinit prompt clint white cyan red yellow |