From 41bd0f01e87e1d5e5fd3d17730bbe25ff119ca04 Mon Sep 17 00:00:00 2001 From: Ambrevar Date: Mon, 13 Aug 2012 17:18:56 +0100 Subject: [PATCH] Shell: big overhaul, error fixes, smart rewrite here and there. Cmus: custom column view. --- .arch-mirrors-edf23ads | 1 - .arch-pkg-aur-edf23ads | 13 +- .arch-pkg-explicit-edf23ads | 159 +++++++---- .arch-pkg-explicit-zeus | 1 - .arch-pkg-official-edf23ads | 272 ++++++++----------- .arch-pkg-official-zeus | 1 - .bashrc | 35 +-- .cmus/autosave | 14 +- .save | 3 + .shell.d/alias_rc | 124 +++++---- .shell.d/colors_rc | 77 ------ .shell.d/funs_bash | 306 ++++++++++----------- .shell.d/funs_rc | 514 ++++++++---------------------------- .shell.d/keys_zsh | 69 +++-- .shell.d/main_rc | 7 +- .shell.d/options_bash | 236 ++++++++--------- .shell.d/options_zsh | 113 ++++---- .zshrc | 35 +-- 18 files changed, 801 insertions(+), 1179 deletions(-) delete mode 100644 .shell.d/colors_rc diff --git a/.arch-mirrors-edf23ads b/.arch-mirrors-edf23ads index 2eb2a840..486ef67c 100644 --- a/.arch-mirrors-edf23ads +++ b/.arch-mirrors-edf23ads @@ -2,5 +2,4 @@ [core] [extra] [community] -[multilib] [archlinuxfr] diff --git a/.arch-pkg-aur-edf23ads b/.arch-pkg-aur-edf23ads index d0f6b85f..780a9e49 100644 --- a/.arch-pkg-aur-edf23ads +++ b/.arch-pkg-aur-edf23ads @@ -1,15 +1,12 @@ bashmount -doxymacs-git dropbox dropbox-cli -emacs-auto-complete-git +emacs-mediawiki-bzr emacs-yasnippet -emacs-yasnippet-latex-git -fbpdf-git -guvcview +grub movgrab -python-unipath +rxvt-unicode-patched submarine trash-cli -vicious-git -wmfs-git +urxvt-keyboard-select +vlc-ncurses diff --git a/.arch-pkg-explicit-edf23ads b/.arch-pkg-explicit-edf23ads index 56c6e50d..3dcf95bb 100644 --- a/.arch-pkg-explicit-edf23ads +++ b/.arch-pkg-explicit-edf23ads @@ -1,6 +1,11 @@ abs acpi alsa-utils +antiword +archlinux-keyring +asciidoc +aspell-en +aspell-fr atool auctex autoconf @@ -12,46 +17,47 @@ bashmount bc binutils bison -blas bzip2 bzr calc -checkinstall -clang -claws-mail +catdvi cmus coreutils +cpufrequtils crda cronie cryptsetup +ctags +cyrus-sasl device-mapper +d-feet dhclient dhcpcd diffutils -doxymacs-git +docbook-xml +docbook-xsl +dosfstools dropbox dropbox-cli -dvgrab +dtach e2fsprogs elfutils -emacs-auto-complete-git emacs-lua-mode +emacs-mediawiki-bzr emacs-nox emacs-yasnippet -emacs-yasnippet-latex-git -evince +expac fakeroot -fbpdf-git +farstream fbv feh fftw file filesystem findutils -firefox -firefox-adblock-plus flashplugin flex +fortune-mod gawk gcc gcc-libs @@ -59,148 +65,209 @@ gcolor2 gdb gettext gimp +git glibc -gnome-themes-standard -gnumeric gnuplot gparted -gpicview gprolog +graphicsmagick grep grub -gtk-aurora-engine -gtk-engines -guvcview +gsasl +gstreamer0.10-bad +gstreamer0.10-bad-plugins +gstreamer0.10-ffmpeg +gstreamer0.10-good +gstreamer0.10-python gzip hdparm heirloom-mailx +help2man highlight htop hunspell-en hunspell-fr +hwids ifplugd +indent inetutils initscripts inkscape +iptables iputils +irssi +ispell +jansson jfsutils -jre7-openjdk +khrplatform-devel ladspa +laptop-mode-tools latex2html latex2rtf less -lib32-v4l-utils libaio libavc1394 +libcdaudio +libdc1394 +libdvdcss +libdvdnav +libdvdread +libegl +libevent +libgme +liblqr +liblrdf +libmediainfo +libmicrohttpd +libmms +libnice +libofa libpipeline -libquicktime +libpurple libstdc++5 +libsystemd libtool +libusbx +libzen licenses -liferea -links +lighttpd linux linux-lts logrotate +lrzip lshw +ltrace +luakit lvm2 -lxde-icon-theme lxterminal +lzo2 m4 make man-db man-pages mdadm -midori +mediainfo +mercurial +mjpegtools movgrab -mplayer +mplayer2 +mtools +musicbrainz +mutt nano +nasm ncdu nmap ntfs-3g ntfsprogs numlockx +openslp openssh p7zip pacman pacman-color +pambase +pari patch pciutils pcmciautils -pdksh perl +perl-locale-gettext +pidgin pkg-config +pkgfile pkgtools -postfix ppp -procps +procps-ng psmisc -pstoedit pwgen +pwsafe +python2-dbus +python2-udiskie +python-configobj +python-dbus-common +python-notify +python-pycurl ranger +raptor reiserfsprogs -rpmextract rtorrent -rxvt-unicode -screen +rxvt-unicode-patched scrot +sdparm sed shadow -skype +slock +soundtouch splint +strace submarine subversion sudo +sxiv sysfsutils syslog-ng sysstat +systemd-tools +sysvbanner sysvinit tar task +tcpdump +texi2html texinfo texlive-genericextra texlive-langextra texlive-latexextra texlive-pictures texlive-science -thunderbird trash-cli tree ttf-dejavu -udev unrar unzip upx +urxvt-keyboard-select usbutils util-linux valgrind vi -vicious-git +vicious +vim +vim-runtime +vlc-ncurses vlock +w3m +weechat wget which +wildmidi +wipe wireless_tools -wmfs-git +wireshark-cli +wireshark-gtk wmname wpa_actiond wpa_supplicant +wv xclip -xcursor-vanilla-dmz-aa xf86-input-synaptics xf86-video-ati xf86-video-vesa -xfconf xfsprogs -xkeycaps xorg-server -xorg-utils -xorg-xdm +xorg-twm +xorg-xev xorg-xinit +xorg-xmessage xorg-xmodmap xorg-xrandr -xpdf -xscreensaver +xorg-xrdb xsel yaourt -zenity +zathura +zathura-djvu +zathura-pdf-poppler +zathura-ps +zip zsh diff --git a/.arch-pkg-explicit-zeus b/.arch-pkg-explicit-zeus index ff6b99d7..3f29df5d 100644 --- a/.arch-pkg-explicit-zeus +++ b/.arch-pkg-explicit-zeus @@ -113,7 +113,6 @@ mediainfo mencoder mercurial mesa-demos -midori mongoose movgrab mplayer2 diff --git a/.arch-pkg-official-edf23ads b/.arch-pkg-official-edf23ads index eb717863..d763ae53 100644 --- a/.arch-pkg-official-edf23ads +++ b/.arch-pkg-official-edf23ads @@ -5,9 +5,14 @@ acl acpi alsa-lib alsa-utils +antiword apr apr-util +archlinux-keyring +asciidoc aspell +aspell-en +aspell-fr ati-dri atk atkmm @@ -24,49 +29,46 @@ bash-completion bc binutils bison -blas -bluez bzip2 bzr ca-certificates -ca-certificates-java +cairo cairomm -cairo-xcb calc -cantarell-fonts +catdvi cdparanoia -checkinstall -cifs-utils -clang -claws-mail cloog cmus -colord compositeproto -consolekit coreutils +cpufrequtils cracklib crda cronie cryptsetup +ctags curl +cyrus-sasl damageproto db dbus dbus-core dbus-glib -dconf desktop-file-utils device-mapper +d-feet dhclient dhcpcd dialog diffutils dirmngr djvulibre -dmxproto +dnssec-anchors +docbook-xml +docbook-xsl +dosfstools dri2proto -dvgrab +dtach e2fsprogs eject elfutils @@ -75,11 +77,12 @@ emacs-nox enca enchant eventlog -evince +expac expat faac faad2 fakeroot +farstream fbv feh ffmpeg @@ -87,14 +90,13 @@ fftw file filesystem findutils -firefox -firefox-adblock-plus fixesproto flac flashplugin flex fontconfig fontsproto +fortune-mod freeglut freetype2 fribidi @@ -104,17 +106,19 @@ gc gcc gcc-libs gcolor2 -gconf gd gdb gdbm gdk-pixbuf2 gegl +geoclue gettext ghostscript giblib giflib gimp +girara-common +girara-gtk2 git glib2 glibc @@ -122,38 +126,36 @@ glibmm glib-networking glproto gmp -gnome-icon-theme -gnome-icon-theme-symbolic -gnome-themes-standard -gnumeric gnupg gnuplot gnutls -goffice gparted gpgme -gpicview gpm gprolog +graphicsmagick grep groff -grub +gsasl gsettings-desktop-schemas gsfonts gsl gsm gstreamer0.10 +gstreamer0.10-bad +gstreamer0.10-bad-plugins gstreamer0.10-base +gstreamer0.10-ffmpeg +gstreamer0.10-good +gstreamer0.10-python gtk2 -gtk3 -gtk-aurora-engine -gtk-engines gtkmm gtkspell gtk-update-icon-cache gzip hdparm heirloom-mailx +help2man hicolor-icon-theme highlight hspell @@ -161,84 +163,45 @@ htop hunspell hunspell-en hunspell-fr +hwids iana-etc -icon-naming-utils icu ifplugd imagemagick imlib2 +indent inetutils initscripts inkscape inputproto iproute2 +iptables iputils +irssi isl +ispell iw jack +jansson jasper -jbig2dec jfsutils -jre7-openjdk -jre7-openjdk-headless json-c -json-glib kbd kbproto keyutils +khrplatform-devel kmod krb5 ladspa lame +laptop-mode-tools latex2html latex2rtf lcms lcms2 +ldns less -lesstif -lib32-alsa-lib -lib32-bzip2 -lib32-dbus-core -lib32-expat -lib32-fontconfig -lib32-freetype2 -lib32-gcc-libs -lib32-glib2 -lib32-glibc -lib32-libdrm -lib32-libffi -lib32-libgl -lib32-libglapi -lib32-libice -lib32-libjpeg-turbo -lib32-libmng -lib32-libpciaccess -lib32-libpng -lib32-libsm -lib32-libtiff -lib32-libx11 -lib32-libxau -lib32-libxcb -lib32-libxcursor -lib32-libxdamage -lib32-libxdmcp -lib32-libxext -lib32-libxfixes -lib32-libxi -lib32-libxrandr -lib32-libxrender -lib32-libxss -lib32-libxv -lib32-libxxf86vm -lib32-openssl -lib32-pcre -lib32-qt -lib32-sqlite3 -lib32-util-linux -lib32-v4l-utils -lib32-zlib libaio -libao libarchive libass libassuan @@ -248,19 +211,22 @@ libavc1394 libbluray libcaca libcap -libcap-ng +libcdaudio libcddb libcdio libcroco libcups libdaemon libdatrie +libdc1394 libdca -libdmx libdrm libdv +libdvdcss +libdvdnav +libdvdread libedit -libetpan +libegl libev libevent libexif @@ -272,31 +238,33 @@ libgee libgl libglade libglapi -libgnome-keyring +libgme libgpg-error -libgphoto2 libgsf libgssglue -libgusb libice libid3tag -libiec61883 -libieee1284 +libidn libirman libjpeg-turbo libksba libldap +liblqr +liblrdf libltdl libmad -libmikmod +libmediainfo +libmicrohttpd +libmms libmng libmodplug libmp4v2 libmpc libmpcdec -libmysqlclient +libnice libnl libnotify +libofa libogg libpcap libpciaccess @@ -304,7 +272,7 @@ libpipeline libpng libproxy libpulse -libquicktime +libpurple libraw1394 librsvg libsamplerate @@ -317,6 +285,7 @@ libsoup libspectre libssh2 libstdc++5 +libsystemd libtasn1 libthai libtheora @@ -325,13 +294,12 @@ libtirpc libtool libtorrent libunique -libusb libusb-compat +libusbx libva libvdpau libvorbis libvpx -libwbclient libwebkit libwmf libx11 @@ -344,7 +312,6 @@ libxdamage libxdg-basedir libxdmcp libxext -libxfce4util libxfixes libxfont libxft @@ -353,7 +320,6 @@ libxinerama libxkbfile libxml2 libxmu -libxp libxpm libxrandr libxrender @@ -362,49 +328,56 @@ libxss libxt libxtst libxv -libxvmc libxxf86dga libxxf86vm +libzen licenses -liferea -links +lighttpd linux linux-api-headers linux-firmware linux-lts lirc-utils -llvm lm_sensors logrotate +lrzip lshw lsof +ltrace lua +luafilesystem +luajit +luakit lvm2 -lxde-icon-theme lxterminal +lzo2 m4 make man-db man-pages mcpp mdadm +mediainfo +mercurial mesa -midori mime-types +mjpegtools mkinitcpio mkinitcpio-busybox mozilla-common mpfr mpg123 -mplayer +mplayer2 mtdev -mupdf +mtools +musicbrainz +mutt nano +nasm ncdu ncurses neon netpbm -net-snmp nettle net-tools nmap @@ -415,6 +388,7 @@ ntfsprogs numlockx opencore-amr openjpeg +openslp openssh openssl orc @@ -425,106 +399,91 @@ pacman pacman-color pacman-mirrorlist pam +pambase pango pangomm +pari parted patch pciutils pcmciautils pcre -pdksh perl -perl-encode-locale perl-error -perl-file-listing -perl-html-parser -perl-html-tagset -perl-http-cookies -perl-http-daemon -perl-http-date -perl-http-message -perl-http-negotiate -perl-libwww -perl-lwp-mediatypes -perl-net-http -perl-uri -perl-www-robotrules -perl-xml-parser -perl-xml-simple -pilot-link +perl-locale-gettext +pidgin pinentry pixman pkg-config +pkgfile pkgtools -plotutils polkit poppler poppler-data poppler-glib popt -portaudio -postfix -postgresql-libs ppl ppp -printproto -procps +procps-ng psmisc -pstoedit pth pwgen +pwsafe pygobject2-devel pygtk python python2 python2-cairo +python2-dbus python2-distribute python2-gobject2 -qt +python2-udiskie +python-configobj +python-dbus-common +python-notify +python-pycurl randrproto ranger +raptor readline recode recordproto reiserfsprogs renderproto -rhino -rpmextract rsync rtmpdump rtorrent run-parts -rxvt-unicode -sane schroedinger -screen scrnsaverproto scrot sdl -sdl_mixer +sdparm sed sg3_utils shadow -shared-color-profiles shared-mime-info -skype -smbclient -smpeg +slock +soundtouch speex splint sqlite startup-notification +strace subversion sudo +sxiv sysfsutils syslog-ng sysstat +systemd-tools +sysvbanner sysvinit t1lib -talloc tar task -tdb +tcpdump +texi2html texinfo texlive-bin texlive-core @@ -533,11 +492,9 @@ texlive-langextra texlive-latexextra texlive-pictures texlive-science -thunderbird tree ttf-dejavu tzdata -udev udisks unixodbc unrar @@ -548,18 +505,27 @@ util-linux v4l-utils valgrind vi +vicious videoproto +vim +vim-runtime vlock vte vte-common -wavpack +w3m +weechat wget which +wildmidi +wipe wireless-regdb wireless_tools +wireshark-cli +wireshark-gtk wmname wpa_actiond wpa_supplicant +wv wxgtk x264 xcb-proto @@ -568,7 +534,6 @@ xcb-util-image xcb-util-keysyms xcb-util-wm xclip -xcursor-vanilla-dmz-aa xdg-utils xextproto xf86dgaproto @@ -577,13 +542,10 @@ xf86-input-synaptics xf86-video-ati xf86-video-vesa xf86vidmodeproto -xfconf xfsprogs xineramaproto xkeyboard-config -xkeycaps xmlrpc-c -xorg-appres xorg-bdftopcf xorg-fonts-alias xorg-fonts-encodings @@ -594,34 +556,28 @@ xorg-mkfontdir xorg-mkfontscale xorg-server xorg-server-common -xorg-sessreg xorg-setxkbmap -xorg-utils +xorg-twm xorg-xauth -xorg-xdm -xorg-xdpyinfo -xorg-xdriinfo xorg-xev xorg-xinit xorg-xkbcomp -xorg-xlsatoms -xorg-xlsclients +xorg-xmessage xorg-xmodmap -xorg-xprop xorg-xrandr xorg-xrdb xorg-xset -xorg-xvinfo -xorg-xwininfo -xpdf xproto -xscreensaver xsel xvidcore xz yajl yaourt -zenity +zathura +zathura-djvu +zathura-pdf-poppler +zathura-ps +zip zlib zsh zziplib diff --git a/.arch-pkg-official-zeus b/.arch-pkg-official-zeus index 188ba0e8..2ecc192a 100644 --- a/.arch-pkg-official-zeus +++ b/.arch-pkg-official-zeus @@ -364,7 +364,6 @@ mencoder mercurial mesa mesa-demos -midori mime-types mjpegtools mkinitcpio diff --git a/.bashrc b/.bashrc index 2f7e7c7c..df865ea5 100644 --- a/.bashrc +++ b/.bashrc @@ -1,6 +1,6 @@ ################################################################################ ## Shell Config -- Master File -## Date 2012-07-02 +## Date 2012-08-11 ################################################################################ ##============================================================================== @@ -8,31 +8,20 @@ ##============================================================================== [ -z "$PS1" ] && return - -##============================================================================== -## Base functions -##============================================================================== - -isShell() -{ - if [ "$1" = "$(ps | grep $$ | awk '{print $4}')" ]; then - return 0 - else - return 1 - fi -} - ##============================================================================== ## Sourcing ##============================================================================== -SHELLDIR="$HOME/.shell.d" +SHELL_CURRENT="$(ps | awk -v shellpid=$$ '$0 ~ shellpid {print $4}')" +SHELL_DIR="$HOME/.shell.d" -source "${SHELLDIR}/main_rc" # Should be sourced first. -source "${SHELLDIR}/options_bash" # Should be sourced first. -source "${SHELLDIR}/colors_rc" # Should be sourced first. +## Should be sourced first. +source "${SHELL_DIR}/main_rc" +source "${SHELL_DIR}/colors_bash" +source "${SHELL_DIR}/options_bash" -source "${SHELLDIR}/funs_rc" -source "${SHELLDIR}/funs_bash" -source "${SHELLDIR}/alias_rc" -source "${SHELLDIR}/personal_rc" +## Source order should not matter. +source "${SHELL_DIR}/alias_rc" +source "${SHELL_DIR}/funs_rc" +source "${SHELL_DIR}/funs_bash" +source "${SHELL_DIR}/personal_rc" diff --git a/.cmus/autosave b/.cmus/autosave index bebb9e7b..66030092 100644 --- a/.cmus/autosave +++ b/.cmus/autosave @@ -1,4 +1,4 @@ -set aaa_mode=album +set aaa_mode=all set altformat_current= %F set altformat_playlist= %f%= %d set altformat_title=%f @@ -33,11 +33,11 @@ set continue=true set display_artist_sort_name=false set dsp.alsa.device=default set dsp.oss.device= -set format_current= %a - %l -%3n. %t%= %y -set format_playlist= %-25%a %3n. %t%= %y %d +set format_current= %a - %y. %l -%3n. %t +set format_playlist= %-18%a %y. %-25%l %3n. %t%= %d set format_playlist_va= %-25%A %3n. %t (%a)%= %y %d -set format_title=%a - %l - %t (%y) -set format_trackwin=%3n. %t%= %y %d +set format_title=%a - %y. %l -%3n. %t +set format_trackwin=%y %3n. %t%= %d [%{codec} %{bitrate} kbps] set format_trackwin_va=%3n. %t (%a)%= %y %d set id3_default_charset=ISO-8859-1 set lib_sort=albumartist date album discnumber tracknumber title filename @@ -49,7 +49,7 @@ set mixer.pulse.restore_volume=1 set output_plugin=alsa set passwd= set pl_sort= -set play_library=false +set play_library=true set play_sorted=false set repeat=false set repeat_current=false @@ -60,7 +60,7 @@ set resume=true set set_term_title=true set show_hidden=false set show_remaining_time=false -set shuffle=false +set shuffle=true set smart_artist_sort=true set softvol=false set softvol_state=0 0 diff --git a/.save b/.save index d89ed797..f55e1bfb 100755 --- a/.save +++ b/.save @@ -196,6 +196,9 @@ do FILELIST=(${FILELIST[*]} "$i") done +## README +FILELIST=(${FILELIST[*]} "README") + ## rtorrent FILELIST=(${FILELIST[*]} ".rtorrent.rc") diff --git a/.shell.d/alias_rc b/.shell.d/alias_rc index b3a1cb2f..a76ba87f 100644 --- a/.shell.d/alias_rc +++ b/.shell.d/alias_rc @@ -8,39 +8,35 @@ ## General ##============================================================================== -# Warning: if this does not work if you change of shell without relogging, use -# 'source .[shell]rc' instead. -if isShell "bash"; then +## Warning: if this does not work if you change shell without relogging, use +## 'source .rc' instead. + +if [ "bash" = "$SHELL_CURRENT" ]; then alias ..='cd ..' alias esrc='$EDITOR ~/.bashrc' alias ssrc='source ~/.bashrc' fi -if isShell "zsh"; then +if [ "zsh" = "$SHELL_CURRENT" ]; then alias esrc='$EDITOR ~/.zshrc' alias ssrc='source ~/.zshrc' fi -## Enable color support of ls and also add handy aliases. -if [ "$TERM" != "dumb" ]; then - eval "`dircolors -b`" -fi - ##============================================================================== ##============================================================================== ## 'ls' redefinition alias ls='ls --color=auto -F -v' -## Listing aliases +## Listing aliases. alias l='ls -1' -alias la='ls -lAh --group-directories-first' # Hidden files +alias la='ls -lAh --group-directories-first' # Hidden files alias lc='ls -ltcrh --group-directories-first' # by change time -alias lk='ls -lSrh --group-directories-first' # by size -alias ll='ls -lh --group-directories-first' # Detailed view with human readable values. -alias lx='ls -lXh --group-directories-first' # sort by extension +alias lk='ls -lSrh --group-directories-first' # by size +alias ll='ls -lh --group-directories-first' # Detailed view with human readable values. +alias lx='ls -lXh --group-directories-first' # sort by extension -# Misc +## Misc alias cp="cp -i" # confirm before overwriting something alias xlx='xrdb -load ~/.Xresources' alias grep='grep --color=auto' @@ -51,36 +47,36 @@ if [ -e "/usr/bin/emacs" ]; then alias emacs-reload="emacsclient -e '(kill-emacs)' >/dev/null 2>&1; /usr/bin/emacs --daemon" fi -# List desktop applications +# List desktop applications. alias applist='grep -r "^Name=" /usr/share/applications/* | cut -d'=' -f2| sort' -## Remove executable attribute +## Remove executable attribute. alias nox='find . -type f -exec chmod a-x {} \;' -## Get your external IP +## Get your external IP. [ -e "/usr/bin/curl" ] && alias myip='curl ifconfig.me' -## Network discovery -[ -e "/usr/bin/nmap" ] && alias netdiscover='nmap -sP "192.168.1.*"' +## Network discovery. +[ -e "/usr/bin/nmap" ] && alias network-discover='nmap -sP "192.168.1.*"' -# Prevents accidentally clobbering files. +## Prevents accidentally clobbering files. alias mkdir='mkdir -p' -# Reset terminal -- Faster alternative of 'reset' +## Reset terminal -- Faster alternative of 'reset'. alias cls='printf "\ec"' -# Display PATH and LD_LIBRARY_PATH in a more readable way +## Display PATH and LD_LIBRARY_PATH in a more readable way. alias echopath='echo -e ${PATH//:/\\n}' alias echolibpath='echo -e ${LD_LIBRARY_PATH//:/\\n}' -## Shutdown / Reboot -## Will only work with consolekit and dbus daemons running. +## Shutdown / Reboot. +## If you do not want to get prompted for your password, configure sudo properly. if [ -e "/usr/bin/dbus-send" ]; then alias halt='sudo halt' alias reboot='sudo reboot' fi -## Start X and lock current terminal (press ENTER when back in terminal to prompt for password) +## Start X and lock current terminal (press ENTER when back in terminal to prompt for password). [ -e "/usr/bin/vlock" ] && alias sx='startx & vlock' ## Screensaver @@ -89,9 +85,6 @@ fi ## Zathura -- Fork to background. [ -e "/usr/bin/zathura" ] && alias zat='zathura --fork' -## Configuration files -[ -e "/etc/rc.conf" ] && alias ercc='sudo $EDITOR /etc/rc.conf' - ## Xrandr alias xmulti='xrandr --output VGA1 --auto --right-of $(xrandr | grep -A1 current | sed -n 2p | awk '"'"'{print $1}'"'"')' alias xmultioff="xrandr --output VGA1 --off" @@ -104,7 +97,7 @@ alias xmorphzi='xrandr --output $(xrandr | grep -A1 current | sed -n 2p | awk '" ## Zsh power aliases ##============================================================================== -# if isShell "zsh"; then +#if [ "zsh" = "$SHELL_CURRENT" ]; then ## Inline aliases, zsh -g aliases can be anywhere in command line #alias -g G='| grep -' #alias -g L='| less' @@ -117,46 +110,49 @@ alias xmorphzi='xrandr --output $(xrandr | grep -A1 current | sed -n 2p | awk '" ##============================================================================== ## Pacman aliases ##============================================================================== -[ -e "/usr/bin/pacman" ] && PACMAN_FRONTEND='pacman' +if [ -e "/usr/bin/pacman" ] ; then -## Use of Pacman-Color -if [ -e "/usr/bin/pacman-color" ]; then - PACMAN_FRONTEND='pacman-color' + PACMAN_FRONTEND='pacman' - if isShell "zsh" ; then - compdef _pacman pacman-color - elif isShell "bash"; then - complete -o default -o nospace -F _pacman pacman-color + ## Use of Pacman-Color + if [ -e "/usr/bin/pacman-color" ]; then + PACMAN_FRONTEND='pacman-color' + + if [ "zsh" = "$SHELL_CURRENT" ]; then + compdef _pacman pacman-color + elif [ "bash" = "$SHELL_CURRENT" ]; then + complete -o default -o nospace -F _pacman pacman-color + fi fi -fi -## Pacman aliases -if [ "$PACMAN_FRONTEND" = "pacman" ]; then - alias pc='sudo pacman -Scc' - alias pi='sudo pacman -S --needed' - alias pqi='pacman -Qi' - alias pql='pacman -Ql' - alias pqo='pacman -Qo' - alias pqs='pacman -Qs' - alias pr='sudo pacman -Rs' - alias psi='pacman -Si' - alias pss='pacman -Ss' - alias pu='sudo pacman -Syu' -fi + ## Pacman aliases + if [ "$PACMAN_FRONTEND" = "pacman" ]; then + alias pc='sudo pacman -Scc' + alias pi='sudo pacman -S --needed' + alias pqi='pacman -Qi' + alias pql='pacman -Ql' + alias pqo='pacman -Qo' + alias pqs='pacman -Qs' + alias pr='sudo pacman -Rs' + alias psi='pacman -Si' + alias pss='pacman -Ss' + alias pu='sudo pacman -Syu' + fi -if [ "$PACMAN_FRONTEND" = "pacman-color" ]; then - alias pc='sudo pacman-color -Scc' - alias pi='sudo pacman -S --needed' - alias pqi='pacman-color -Qi' - alias pql='pacman-color -Ql' - alias pqo='pacman-color -Qo' - alias pqs='pacman-color -Qs' - alias pr='sudo pacman-color -Rs' - alias psi='pacman-color -Si' - alias pss='pacman-color -Ss' - alias pu='sudo pacman-color -Syu' -fi + if [ "$PACMAN_FRONTEND" = "pacman-color" ]; then + alias pc='sudo pacman-color -Scc' + alias pi='sudo pacman -S --needed' + alias pqi='pacman-color -Qi' + alias pql='pacman-color -Ql' + alias pqo='pacman-color -Qo' + alias pqs='pacman-color -Qs' + alias pr='sudo pacman-color -Rs' + alias psi='pacman-color -Si' + alias pss='pacman-color -Ss' + alias pu='sudo pacman-color -Syu' + fi +fi ##============================================================================== ## TeXlive aliases diff --git a/.shell.d/colors_rc b/.shell.d/colors_rc deleted file mode 100644 index fbe3d315..00000000 --- a/.shell.d/colors_rc +++ /dev/null @@ -1,77 +0,0 @@ -## -*- mode:sh -*- # -##============================================================================== -## Colors for universal support -##============================================================================== - -## Reset -Color_Off='\e[0m' # Text Reset - -## Regular Colors -Black='\e[0;30m' # Black -Red='\e[0;31m' # Red -Green='\e[0;32m' # Green -Yellow='\e[0;33m' # Yellow -Blue='\e[0;34m' # Blue -Purple='\e[0;35m' # Purple -Cyan='\e[0;36m' # Cyan -White='\e[0;37m' # White - -## Bold -BBlack='\e[1;30m' # Black -BRed='\e[1;31m' # Red -BGreen='\e[1;32m' # Green -BYellow='\e[1;33m' # Yellow -BBlue='\e[1;34m' # Blue -BPurple='\e[1;35m' # Purple -BCyan='\e[1;36m' # Cyan -BWhite='\e[1;37m' # White - -## Underline -UBlack='\e[4;30m' # Black -URed='\e[4;31m' # Red -UGreen='\e[4;32m' # Green -UYellow='\e[4;33m' # Yellow -UBlue='\e[4;34m' # Blue -UPurple='\e[4;35m' # Purple -UCyan='\e[4;36m' # Cyan -UWhite='\e[4;37m' # White - -## Background -On_Black='\e[40m' # Black -On_Red='\e[41m' # Red -On_Green='\e[42m' # Green -On_Yellow='\e[43m' # Yellow -On_Blue='\e[44m' # Blue -On_Purple='\e[45m' # Purple -On_Cyan='\e[46m' # Cyan -On_White='\e[47m' # White - -## High Intensty -IBlack='\e[0;90m' # Black -IRed='\e[0;91m' # Red -IGreen='\e[0;92m' # Green -IYellow='\e[0;93m' # Yellow -IBlue='\e[0;94m' # Blue -IPurple='\e[0;95m' # Purple -ICyan='\e[0;96m' # Cyan -IWhite='\e[0;97m' # White - -## Bold High Intensty -BIBlack='\e[1;90m' # Black -BIRed='\e[1;91m' # Red -BIGreen='\e[1;92m' # Green -BIYellow='\e[1;93m' # Yellow -BIBlue='\e[1;94m' # Blue -BIPurple='\e[1;95m' # Purple -BICyan='\e[1;96m' # Cyan -BIWhite='\e[1;97m' # White - -## High Intensty backgrounds -On_IBlack='\e[0;100m' # Black -On_IRed='\e[0;101m' # Red -On_IGreen='\e[0;102m' # Green -On_IYellow='\e[0;103m' # Yellow -On_IBlue='\e[0;104m' # Blue -On_IPurple='\e[10;95m' # Purple -On_ICyan='\e[0;106m' # Cyan -On_IWhite='\e[0;107m' # White diff --git a/.shell.d/funs_bash b/.shell.d/funs_bash index 29629245..32b352c8 100644 --- a/.shell.d/funs_bash +++ b/.shell.d/funs_bash @@ -1,175 +1,177 @@ ## -*- mode:sh -*- # ################################################################################ ## Bash specific functions +## WARNING: this file needs a serious update and rewrite! ################################################################################ -if isShell "bash"; then - ##============================================================================== ## Browse History ##============================================================================== -# Parameters usage -- should be set before sourcing the function. + +## Parameters usage -- should be set before sourcing the function. +if [ -d "$SHELLDIR" ]; then + BHISTORY="${SHELLDIR}/bhistory" +else + BHISTORY="$HOME/.bhistory" +fi +BHISTFILESIZE=20 +BHISTREVERT=true +BHISTLOADLAST=true + + +## Where to store the history file. +if [ "$BHISTORY" == "" ]; then if [ -d "$SHELLDIR" ]; then BHISTORY="${SHELLDIR}/bhistory" else BHISTORY="$HOME/.bhistory" fi - BHISTFILESIZE=20 - BHISTREVERT=true - BHISTLOADLAST=true +fi + +## History prompted to the user. +## BHISTFILESIZE +1 entry are stored, the additional one +## is for the current directory to be remembered for new session. +[ "$BHISTFILESIZE" == "" ] && BHISTFILESIZE=20 + +## If true, first listed is last browsed. +[ "$BHISTREVERT" == "" ] && BHISTREVERT=true + +## Go back to previous folder when starting a new session. +[ "$BHISTLOADLAST" == "" ] && BHISTLOADLAST=true -# Where to store the history file. - if [ "$BHISTORY" == "" ]; then - if [ -d "$SHELLDIR" ]; then - BHISTORY="${SHELLDIR}/bhistory" - else - BHISTORY="$HOME/.bhistory" - fi - fi -# History prompted to the user. -# BHISTFILESIZE +1 entry are stored, the additional one -# is for the current directory to be remembered for new session. - [ "$BHISTFILESIZE" == "" ] && BHISTFILESIZE=20 +## Prevent infinite recursiveness when sourcing multiple times. +unalias cd>/dev/null 2>&1 -# If true, first listed is last browsed. - [ "$BHISTREVERT" == "" ] && BHISTREVERT=true +## SEED is used to generate uniq filenames. +SEED=$(date "+%y-%m-%d-%H%M%S") -# Go back to previous folder when starting a new session. - [ "$BHISTLOADLAST" == "" ] && BHISTLOADLAST=true +## Makes sure destination folder exists. +mkdir -p $(dirname "$BHISTORY") + +## Use 'head' or 'tail' depending on BHISTREVERT +if $BHISTREVERT; then + BFUNC=head + BFUNCREV=tail + touch "${BHISTORY}-true" + if [ -e "$BHISTORY" -a -e "${BHISTORY}-false" ]; then + rm -rf "${BHISTORY}-false" + touch "${BHISTORY}-${SEED}_REV" + tac "$BHISTORY" > "${BHISTORY}_${SEED}_REV" + cat "${BHISTORY}_${SEED}_REV" > "$BHISTORY" + rm -rf "${BHISTORY}_${SEED}_REV" + fi +else + BFUNC=tail + BFUNCREV=head + touch "${BHISTORY}-false" + if [ -e "$BHISTORY" -a -e "${BHISTORY}-true" ]; then + rm -rf "${BHISTORY}-true" + touch "${BHISTORY}-${SEED}_REV" + tac "$BHISTORY" > "${BHISTORY}_${SEED}_REV" + cat "${BHISTORY}_${SEED}_REV" > "$BHISTORY" + rm -rf "${BHISTORY}_${SEED}_REV" + fi +fi -# Prevent infinite recursiveness when sourcing multiple times. - unalias cd>/dev/null 2>&1 - -# SEED is used to generate uniq filenames. - SEED=$(date "+%y-%m-%d-%H%M%S") - -# Makes sure destination folder exists. - mkdir -p $(dirname "$BHISTORY") - -# Use 'head' or 'tail' depending on BHISTREVERT - if $BHISTREVERT; then - BFUNC=head - BFUNCREV=tail - touch "${BHISTORY}-true" - if [ -e "$BHISTORY" -a -e "${BHISTORY}-false" ]; then - rm -rf "${BHISTORY}-false" - touch "${BHISTORY}-${SEED}_REV" - tac "$BHISTORY" > "${BHISTORY}_${SEED}_REV" - cat "${BHISTORY}_${SEED}_REV" > "$BHISTORY" - rm -rf "${BHISTORY}_${SEED}_REV" - fi - else - BFUNC=tail - BFUNCREV=head - touch "${BHISTORY}-false" - if [ -e "$BHISTORY" -a -e "${BHISTORY}-true" ]; then - rm -rf "${BHISTORY}-true" - touch "${BHISTORY}-${SEED}_REV" - tac "$BHISTORY" > "${BHISTORY}_${SEED}_REV" - cat "${BHISTORY}_${SEED}_REV" > "$BHISTORY" - rm -rf "${BHISTORY}_${SEED}_REV" - fi - fi +## Go back to previous folder when starting a new session. +## Need to put this part before the new 'cd' is set to prevent $HOME from being added as last entry in the history. +if [ $BHISTLOADLAST -a -e $BHISTORY ]; then + LASTPATH="$($BFUNC -n1 $BHISTORY)" + if [[ -e "$LASTPATH" ]]; then + cd "$LASTPATH" + fi + unset LASTPATH +fi -# Go back to previous folder when starting a new session. -# Need to put this part before the new 'cd' is set to prevent $HOME from being added as last entry in the history. - if [ $BHISTLOADLAST -a -e $BHISTORY ]; then - LASTPATH="$($BFUNC -n1 $BHISTORY)" - if [[ -e "$LASTPATH" ]]; then - cd "$LASTPATH" - fi - unset LASTPATH - fi - - - function bcd(){ - # First character is an hyphen. - if [ "${1:0:1}" == "-" ]; then - if [ ${#1} -eq 1 ]; then # cd - - cd - - else - DEST=${1:1} # After the hyphen +function bcd(){ + ## First character is an hyphen. + if [ "${1:0:1}" == "-" ]; then + if [ ${#1} -eq 1 ]; then # cd - + cd - + else + DEST=${1:1} # After the hyphen # Check if the content after the hyphen is a number. - if [[ $DEST == ${DEST//[^0-9]/} ]]; then - let DEST=$DEST # Set DEST as an integer only here to avoid errors. + if [[ $DEST == ${DEST//[^0-9]/} ]]; then + let DEST=$DEST # Set DEST as an integer only here to avoid errors. - if $BHISTREVERT; then - let DEST=${DEST}+1 - fi + if $BHISTREVERT; then + let DEST=${DEST}+1 + fi - NEWPATH=$(head -n$DEST "$BHISTORY"|tail -n1) - echo ${NEWPATH} - cd "${NEWPATH}" - else - cd "$1" - fi - fi - else - if [ -z "$1" ]; then - cd - else - cd "$1" - fi - fi + NEWPATH=$(head -n$DEST "$BHISTORY"|tail -n1) + echo ${NEWPATH} + cd "${NEWPATH}" + else + cd "$1" + fi + fi + else + if [ -z "$1" ]; then + cd + else + cd "$1" + fi + fi ## Let's update the history. - touch $BHISTORY + touch $BHISTORY - # A buffer is used to avoid flow errors. - if $BHISTREVERT; then - echo ${PWD} >> "${BHISTORY}_$SEED" - cat "$BHISTORY" >> "${BHISTORY}_$SEED" - else - cat "$BHISTORY" >> "${BHISTORY}_$SEED" - echo "${PWD}" >> "${BHISTORY}_$SEED" - fi + ## A buffer is used to avoid flow errors. + if $BHISTREVERT; then + echo ${PWD} >> "${BHISTORY}_$SEED" + cat "$BHISTORY" >> "${BHISTORY}_$SEED" + else + cat "$BHISTORY" >> "${BHISTORY}_$SEED" + echo "${PWD}" >> "${BHISTORY}_$SEED" + fi - # The 'awk' command makes sure there is duplicates. - # If the history size is beyond the limit set by $BHISTFILESIZE+1, it is cut. - # The '+1' is for storing the current folder which is not displayed to the used. - let BHISTSIZEREAL=${BHISTFILESIZE}+1 - awk ' !x[$0]++' "${BHISTORY}_$SEED" | $BFUNC -n $BHISTSIZEREAL > "$BHISTORY" + ## The 'awk' command makes sure there is duplicates. + ## If the history size is beyond the limit set by $BHISTFILESIZE+1, it is cut. + ## The '+1' is for storing the current folder which is not displayed to the used. + let BHISTSIZEREAL=${BHISTFILESIZE}+1 + awk ' !x[$0]++' "${BHISTORY}_$SEED" | $BFUNC -n $BHISTSIZEREAL > "$BHISTORY" - rm "${BHISTORY}_$SEED" - } + rm "${BHISTORY}_$SEED" +} - function bhistory(){ - if [ ! -e "$BHISTORY" ]; then - echo "Browse history empty" - else - let BHISTDISPLAY=$(cat "$BHISTORY"| wc -l)-1 - $BFUNCREV -n$BHISTDISPLAY "$BHISTORY"| cat -n - fi - } +function bhistory(){ + if [ ! -e "$BHISTORY" ]; then + echo "Browse history empty" + else + let BHISTDISPLAY=$(cat "$BHISTORY"| wc -l)-1 + $BFUNCREV -n$BHISTDISPLAY "$BHISTORY"| cat -n + fi +} -# Clean -- buggy? +## Clean -- buggy? #unset BFUNC BFUNCREV SEED BHISTSIZEREAL -# Replace 'cd' command - alias cd='bcd' +## Replace 'cd' command +alias cd='bcd' - shopt -s extglob # To allow bash to understand generic expression - shopt -s progcomp # To enable the programmable completion - set +o nounset # Otherwise some completions will fail - complete -A directory cd +shopt -s extglob ## To allow bash to understand generic expression +shopt -s progcomp ## To enable the programmable completion +set +o nounset ## Otherwise some completions will fail +complete -A directory cd ##============================================================================== ## Alias auto completion ##============================================================================== -# wrap_alias takes three arguments: -# $1: The name of the alias -# $2: The command used in the alias -# $3: The arguments in the alias all in one string -# Generate a wrapper completion function (completer) for an alias -# based on the command and the given arguments, if there is a -# completer for the command, and set the wrapper as the completer for -# the alias. +## wrap_alias takes three arguments: +## $1: The name of the alias +## $2: The command used in the alias +## $3: The arguments in the alias all in one string +## Generate a wrapper completion function (completer) for an alias +## based on the command and the given arguments, if there is a +## completer for the command, and set the wrapper as the completer for +## the alias. + #function wrap_alias() { # [[ "$#" == 3 ]] || return 1 # @@ -178,28 +180,28 @@ if isShell "bash"; then # local alias_arguments="$3" # local num_alias_arguments=$(echo "$alias_arguments" | wc -w) # -# # The completion currently being used for the aliased command. +# ## The completion currently being used for the aliased command. # local completion=$(complete -p $aliased_command 2> /dev/null) # -# # Only a completer based on a function can be wrapped so look for -F -# # in the current completion. This check will also catch commands -# # with no completer for which $completion will be empty. +# ## Only a completer based on a function can be wrapped so look for -F +# ## in the current completion. This check will also catch commands +# ## with no completer for which $completion will be empty. # echo $completion | grep -q -- -F || return 0 # # local namespace=alias_completion:: # -# # Extract the name of the completion function from a string that -# # looks like: something -F function_name something -# # First strip the beginning of the string up to the function name by -# # removing "* -F " from the front. +# ## Extract the name of the completion function from a string that +# ## looks like: something -F function_name something +# ## First strip the beginning of the string up to the function name by +# ## removing "* -F " from the front. # local completion_function=${completion##* -F } -# # Then strip " *" from the end, leaving only the function name. +# ## Then strip " *" from the end, leaving only the function name. # completion_function=${completion_function%% *} # -# # Try to prevent an infinite loop by not wrapping a function -# # generated by this function. This can happen when the user runs -# # this twice for an alias like ls='ls --color=auto' or alias l='ls' -# # and alias ls='l foo' +# ## Try to prevent an infinite loop by not wrapping a function +# ## generated by this function. This can happen when the user runs +# ## this twice for an alias like ls='ls --color=auto' or alias l='ls' +# ## and alias ls='l foo' # [[ "${completion_function#$namespace}" != $completion_function ]] && return 0 # # local wrapper_name="${namespace}${alias_name}" @@ -213,20 +215,18 @@ if isShell "bash"; then # } #" # - # To create the new completion we use the old one with two - # replacements: - # 1) Replace the function with the wrapper. +# ## To create the new completion we use the old one with two +# ## replacements: +# ## 1) Replace the function with the wrapper. # local new_completion=${completion/-F * /-F $wrapper_name } - # 2) Replace the command being completed with the alias. +# ## 2) Replace the command being completed with the alias. # new_completion="${new_completion% *} $alias_name" - +# # eval "$new_completion" #} -# For each defined alias, extract the necessary elements and use them -# to call wrap_alias. +## For each defined alias, extract the necessary elements and use them +## to call wrap_alias. #eval "$(alias -p | sed -e 's/alias \([^=][^=]*\)='\''\([^ ][^ ]*\) *\(.*\)'\''/wrap_alias \1 \2 '\''\3'\'' /')" #unset wrap_alias - -fi diff --git a/.shell.d/funs_rc b/.shell.d/funs_rc index 897d10b6..9023a3fa 100644 --- a/.shell.d/funs_rc +++ b/.shell.d/funs_rc @@ -1,13 +1,27 @@ ## -*- mode:sh -*- # ################################################################################ ## Shell -- Functions. -## Date 2012-06-21 +## Date 2012-08-11 ################################################################################ -## Make dir and go into it. +## Colored man pager. +man() +{ + env \ + LESS_TERMCAP_mb=$(printf "\e[1;31m") \ + LESS_TERMCAP_md=$(printf "\e[1;31m") \ + LESS_TERMCAP_me=$(printf "\e[0m") \ + LESS_TERMCAP_se=$(printf "\e[0m") \ + LESS_TERMCAP_so=$(printf "\e[1;44;33m") \ + LESS_TERMCAP_ue=$(printf "\e[0m") \ + LESS_TERMCAP_us=$(printf "\e[1;32m") \ + man "$@" +} + +## Make directories and change into the first one. mkcd () { - mkdir -p "$*" - cd "$*" + mkdir -p "$@" + cd "$1" } ## Quick search. @@ -25,6 +39,7 @@ cuttail() } ## Cut first n lines in file, 10 by default. +## TODO: use sed command instead. cuthead() { local nlines=${2:-10} @@ -41,13 +56,12 @@ renamelower() for file ; do filename=${file##*/} - case "$filename" in - */*) - dirname==${file%/*} ;; - *) - dirname=.;; - esac + case "$filename" in + */*) dirname="${file%/*}" ;; + *) dirname="." ;; + esac + local nf=$(echo $filename | tr A-Z a-z) local newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then @@ -62,10 +76,10 @@ renamelower() ## Swap 2 filenames around. renameswap() { - local TMPFILE=tmp.$$ - mv "$1" $TMPFILE + local TEMPFILE="$(mktemp)" + mv "$1" "$TEMPFILE" mv "$2" "$1" - mv $TMPFILE "$2" + mv "$TEMPFILE" "$2" } ## Finds directory sizes and lists them for the current directory. @@ -74,15 +88,15 @@ dirsize () local TEMPFILE="$(mktemp)" # du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \ du -shx * 2> /dev/null | \ - egrep '^ *[0-9.]*[MG]' | sort -n > ${TEMPFILE} - egrep '^ *[0-9.]*M' ${TEMPFILE} - egrep '^ *[0-9.]*G' ${TEMPFILE} - rm -rf ${TEMPFILE} + egrep '^ *[0-9.]*[MG]' | sort -n > "${TEMPFILE}" + egrep '^ *[0-9.]*M' "${TEMPFILE}" + egrep '^ *[0-9.]*G' "${TEMPFILE}" + rm -rf "${TEMPFILE}" } ## Network operations if [ -e "/usr/bin/nmap" ]; then - networkmap() { + network-map() { echo "$1" for SCANIP in $( nmap -sL "$1" | grep -i "\([[:digit:]]\+\.\)\{3,\}[[:digit:]]\+" | awk '{print $5}' ); do sudo nmap -oX - -n -sT -T Normal -O -sR -I -F -P0 "$SCANIP" @@ -91,8 +105,8 @@ if [ -e "/usr/bin/nmap" ]; then } fi -## Vim-only: search the vim reference manual for a keyword -## usage: :h +## Vim-only: search the vim reference manual for a keyword. +## Usage: :h if [ -e "/usr/bin/vim" ]; then :h() { @@ -129,21 +143,21 @@ asciify() for i; do sed -i \ - -e 's/[àáâä]/a/g' \ - -e 's/[éèêë]/e/g' \ - -e 's/[ïîí]/i/g' \ - -e 's/[öôó]/o/g' \ - -e 's/[ùúûü]/u/g' \ - -e 's/[À]/A/g' \ - -e 's/[ÉÈ]/E/g' \ - -e 's/[ñ]/n/g' \ - -e 's/[œ]/oe/g' \ - -e 's/[Œ]/Oe/g' \ - -e 's/[æ]/ae/g' \ - -e 's/[Æ]/Ae/g' \ - -e 's/[ç]/c/g' \ - -e 's/[Ç]/C/g' \ - "$i" + -e 's/[àáâä]/a/g' \ + -e 's/[éèêë]/e/g' \ + -e 's/[ïîí]/i/g' \ + -e 's/[öôó]/o/g' \ + -e 's/[ùúûü]/u/g' \ + -e 's/[À]/A/g' \ + -e 's/[ÉÈ]/E/g' \ + -e 's/[ñ]/n/g' \ + -e 's/[œ]/oe/g' \ + -e 's/[Œ]/Oe/g' \ + -e 's/[æ]/ae/g' \ + -e 's/[Æ]/Ae/g' \ + -e 's/[ç]/c/g' \ + -e 's/[Ç]/C/g' \ + "$i" done; } @@ -176,11 +190,13 @@ blind-append() STRING="$2" fi + echo -n "Secret: " read -s DUMMY + echo "" if [ ! -e "$FILE" ] || [ "$STRING" = "" ]; then echo "$DUMMY" >> "$FILE" - echo "Secrect blindly appended to ${FILE} at the end." + echo "Secret appended to ${FILE} at the end." return fi @@ -190,11 +206,10 @@ blind-append() else sed -i "s/${STRING}/${STRING}${DUMMY}/g" "${FILE}" fi - echo "Secret blindly appended to ${FILE}." + echo "Secret appended to ${FILE}." return } - ## Term properties termcolors(){ x=$(tput op) @@ -217,45 +232,27 @@ termsupport() done | sort -nk2 } -## Colored man pager. -man() -{ - env \ - LESS_TERMCAP_mb=$(printf "\e[1;31m") \ - LESS_TERMCAP_md=$(printf "\e[1;31m") \ - LESS_TERMCAP_me=$(printf "\e[0m") \ - LESS_TERMCAP_se=$(printf "\e[0m") \ - LESS_TERMCAP_so=$(printf "\e[1;44;33m") \ - LESS_TERMCAP_ue=$(printf "\e[0m") \ - LESS_TERMCAP_us=$(printf "\e[1;32m") \ - man "$@" -} - ## Highlight themes viewer for 256-colors terminals. -hlt-viewer () -{ - print_help() +if [ -f "/usr/bin/highlight" ] ; then + hlt-viewer () { - echo "Synopsis:" - echo -e " $1" - echo - echo "This script displays a preview for every highlight's theme." - echo "Press ENTER to display next preview. Press anything else then ENTER to quit." - } - - if [ ! -f "/usr/bin/highlight" ];then - echo "Please install 'highlight'." - return - fi - - if [ $# -gt 0 ]; then - print_help "$0" - return - fi + print_help() + { + echo "Synopsis:" + echo -e " $1" + echo + echo "This script displays a preview for every highlight's theme." + echo "Press ENTER to display next preview. Press anything else then ENTER to quit." + } + + if [ $# -gt 0 ]; then + print_help "$0" + return + fi - local LIST=$(highlight -w | grep -v "\s\|^$") - local SAMPLE="void function(char* pointer, int &ref) + local LIST=$(highlight -w | grep -v "\s\|^$") + local SAMPLE="void function(char* pointer, int &ref) { int integer=3; char* string=\"Hello!\"; @@ -267,41 +264,42 @@ hlt-viewer () } }" - unset DUMMY - for i in $(highlight -w | grep -v "\s\|^$"); do - echo "******************** $i ********************" - highlight -S c -O xterm256 <(echo $SAMPLE) -s "$i" - read -s DUMMY - if [ ! "$DUMMY" = "" ];then - return - fi - done -} + unset DUMMY + for i in $(highlight -w | grep -v "\s\|^$"); do + echo "******************** $i ********************" + highlight -S c -O xterm256 <(echo $SAMPLE) -s "$i" + read -s DUMMY + if [ ! "$DUMMY" = "" ];then + return + fi + done + } +fi ## Extractor -- Useless when using 'atool'. if [ ! -e "/usr/bin/atool" ]; then extract () { - if [ -f $1 ] ; then - case $1 in - *.tar.bz2) tar xvjf $1 ;; - *.tar.gz) tar xvzf $1 ;; - *.tar.xz) tar xvJf $1 ;; - *.bz2) bunzip2 $1 ;; - *.rar) unrar x $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar xvf $1 ;; - *.tbz2) tar xvjf $1 ;; - *.tgz) tar xvzf $1 ;; - *.zip) unzip $1 ;; - *.Z) uncompress $1 ;; - *.7z) 7z x $1 ;; - *.xz) unxz $1 ;; - *.exe) cabextract $1 ;; - *) echo "\`$1': unrecognized file compression" ;; - esac - else - echo "\`$1' is not a valid file" - fi + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xvjf $1 ;; + *.tar.gz) tar xvzf $1 ;; + *.tar.xz) tar xvJf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xvf $1 ;; + *.tbz2) tar xvjf $1 ;; + *.tgz) tar xvzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; + *.7z) 7z x $1 ;; + *.xz) unxz $1 ;; + *.exe) cabextract $1 ;; + *) echo "\`$1': unrecognized file compression" ;; + esac + else + echo "\`$1' is not a valid file" + fi } fi @@ -432,7 +430,7 @@ archive () } # This function will clean TeX/LaTeX project folders recursively. -function texclean () +texclean () { if [ -z "$1" ]; then WORKDIR="$PWD" @@ -535,7 +533,7 @@ formatc() # ## Function parenthesis # sed -i 's/\([^ ]\)(/\1 (/g' "$FILE" # sed -i 's/\s\s\+(/ (/g' "$FILE" - + # ## Semicolon # sed -i 's/\([^ ]\);/\1 ;/g' "$FILE" # sed -i 's/;\([^ ]\)/; \1/g' "$FILE" @@ -598,8 +596,11 @@ bindatasearch() ## The awk command suppresses first column, spaces and line breaks. local SOURCE=$(od -tx8 "$1" | awk '($1="")1 gsub ( /\s/,"") { printf ("%s", $0) }') - - ## Solution 1 + ## This special, not well-known syntax allows us to execute a set of + ## functions of the result of find. Since everything MUST be between simple + ## quotes, we cannot use external varaibles directly. So we pass the $SOURCE + ## varaible as argument. The underscore at the end allow the use of + ## arguments. find "$WORKDIR" -type f -exec bash -c ' TARGET=$(od -tx8 "$1" | awk '"'"'($1="")1 gsub ( /\s/,"") { printf ("%s", $0) }'"'"') grep -q "$2" <(echo $TARGET) @@ -613,301 +614,9 @@ bindatasearch() ##============================================================================== if [ -f "/usr/bin/pacman" ]; then - -## TODO: completion does not work as is. It requires pacman arguments like -S or -Q. -## There should be a way to use it. -# if isShell "zsh" ; then -# compdef _pacman pacman-deps -# elif isShell "bash"; then -# complete -o default -o nospace -F _pacman pacman-deps -# fi - -## This function gets the pacman variabless when necessary. -## Note: some functions uses pacman localized output. It should work in any case. -## Note: you should always call _pacman_unset_vars in the end. -_pacman_set_vars() -{ - local pacman_var_list="$(pacman -Qi tzdata | cut -f1 -d':')" - if [ "$pacman_var_list" = "" ];then - echo "Could not get pacman's variables." - return 2 - fi - - pacman_name="$(echo "$pacman_var_list" | sed -n '1p')" - pacman_deps="$(echo "$pacman_var_list" | sed -n '7p')" - pacman_optdeps="$(echo "$pacman_var_list" | sed -n '8p')" - pacman_size="$(echo "$pacman_var_list" | sed -n '12p')" -} - -_pacman_unset_vars() -{ - unset pacman_name - unset pacman_deps - unset pacman_optdeps - unset pacman_size -} - -## Get detailed file size list for the specified packages. -if [ -f "/usr/bin/pacman" ]; then - pacman-files() - { - printhelp() - { - echo "Synopsis:" - echo -e " $1 [-n] PACKAGES" - echo - echo "Usage:" - echo -e " default:\tDisplay file size of PACKAGES." - echo -e " -h:\t\tDisplay this help." - echo -e " -n:\t\tSort by size." - } - - local OPTION_SORT="cat" - - while getopts ":hn" opt; do - case $opt in - h) - printhelp "$0" - return 1 - ;; - n) - OPTION_SORT="sort -h" - ;; - ?) - printhelp "$0" - return 1 - ;; - :) - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - ;; - esac - done - - shift $(($OPTIND - 1)) - - if [ $# -eq 0 ]; then - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - fi - - local RESULT_HUMAN="$(du -bh $(pacman -Qlq "$@" | grep -v ".*/$" | sort -u) | eval ${OPTION_SORT})" - local RESULT="$(du -b $(pacman -Qlq "$@" | grep -v ".*/$" | sort -u))" - echo "${RESULT_HUMAN}" - - echo "$RESULT" | awk -F "[[:alpha:]]" '{TOTAL=$1+TOTAL} END {printf("Total: %d KiB\n",TOTAL/1024)}' - } + source "${SHELL_DIR}/funs_pacman" fi -## Retrieve official packages list. -if [ -f "/usr/bin/pacman" ]; then - pacman-official() - { - # Alternative 'diff' verision. - # diff <(pacman -Qq | sort) <(pacman -Qmq | sort) --new-line-format='' --unchanged-group-format='%>' - - comm -3 <(pacman -Qq | sort) <(pacman -Qmq | sort) - } -fi - -## Compare installed packages with list. -if [ -f "/usr/bin/pacman" ]; then - pacman-diff() - { - printhelp() - { - echo "Synopsis:" - echo -e " $1 [-m|-e] [-q] FILE" - echo - echo "Usage:" - echo -e " default:\tDisplay packages included in FILE but not installed." - echo -e " -e:\t\tCompare FILE to explicitly installed packages." - echo -e " -h:\t\tDisplay this help." - echo -e " -m:\t\tCompare FILE to foreign installed packages." - echo -e " -q:\t\tDisplay installed packages not included in FILE." - } - - local OPTION_EXPLICIT="" - local OPTION_FOREIGN="" - local OPTION_LOCAL="-1" - - while getopts ":hmqe" opt; do - case $opt in - e) - OPTION_EXPLICIT="e" - ;; - h) - printhelp "$0" - return 1 - ;; - m) - OPTION_FOREIGN="m" - ;; - q) - OPTION_LOCAL="-2" - ;; - ?) - printhelp "$0" - return 1 - ;; - :) - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - ;; - esac - done - - shift $(($OPTIND - 1)) - - if [ $# -eq 0 ]; then - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - fi - - comm -3 ${OPTION_LOCAL} <(pacman -Qq${OPTION_FOREIGN}${OPTION_EXPLICIT} | sort) <(sort "$*") - - } -fi - -## Print specified package size and a grand total. -if [ -f "/usr/bin/pacman" ]; then - pacman-size() - { - printhelp() - { - echo "Synopsis:" - echo -e " $1 [-a|-h|-n|-q] PACKAGES" - echo -e " Arguments MUST be set before package list." - echo - echo "Usage:" - echo -e " default:\tDisplay package size. Output contains no double and is alphabetically sorted. A grand total is printed at the end. It will only work for repos packages by default." - echo -e " -h:\t\tShow this help." - echo -e " -n:\t\tOutput is sorted by size." - echo -e " -q:\t\tUses installed packages database instead of repos database. It speeds up queries and allows displaying size of local packages not available in repos." - } - - local CMD="pacman -Si" - local SEP=": " - local TOTAL_SIZE=0 - local SORT="sort -u -k3" - local SORT_SIZE="cat" - - while getopts ":hnq" opt; do - case $opt in - h) - printhelp "$0" - return 1 - ;; - n) - SORT_SIZE="sort -n" - ;; - q) - CMD="pacman -Qi" - ;; - ?) - printhelp "$0" - return 1 - ;; - :) - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - ;; - esac - done - - shift $(($OPTIND - 1)) - - if [ $# -eq 0 ]; then - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - fi - - _pacman_set_vars - - local RESULT=$(eval "${CMD} $@" | awk -F "$SEP" -v filter="$pacman_size" -v pkg="$pacman_name" \ - '$0 ~ pkg {pkgname=$2} $0 ~ filter {gsub(/\..*/,"") ; printf("%6s KiB %s\n", $2, pkgname)}' | eval "$SORT" | eval "$SORT_SIZE") - - echo "$RESULT" - - ## Print total size. - echo "$RESULT" | awk '{TOTAL=$1+TOTAL} END {printf("Total: %d KiB\n",TOTAL)}' - - ## One line version. ~ same performance. - # eval "${CMD} $@ 2>/dev/null" | awk -F "$SEP" -v filter="$pacman_size" -v pkg="$pacman_name" \ - # '$0 ~ pkg {pkgname=$2} $0 ~ filter {gsub(/\..*/,"") ; printf("%6s KiB %s\n", $2, pkgname)}' | sort -u -k3 \ - # | tee >(awk '{TOTAL=$1+TOTAL} END {printf("Total: %d KiB\n",TOTAL)}') - - _pacman_unset_vars - } -fi - -## Print deps list. -if [ -f "/usr/bin/pacman" ]; then - pacman-deps() - { - printhelp() - { - echo "Synopsis:" - echo -e " $1 [-a|-h|-q] PACKAGES" - echo -e " Arguments MUST be set before package list." - echo - echo "Usage:" - echo -e " default:\tDisplay package dependencies. Output contains no double and is alphabetically sorted. It will only work for repos packages by default." - echo -e " -a:\t\tUses Yaourt queries instead of repos database. It slows down query but allow displaying size of local any packages not available in repos." - echo -e " -h:\t\tShow this help." - echo -e " -q:\t\tUses installed packages database instead of repos database. It speeds up queries and allows displaying size of local packages not available in repos." - } - - local CMD="pacman -Si" - local SEP=": " - - while getopts ":ahq" opt; do - case $opt in - a) - CMD="yaourt -Si" - ;; - h) - printhelp "$0" - return 1 - ;; - q) - CMD="pacman -Qi" - ;; - ?) - printhelp "$0" - return 1 - ;; - :) - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - ;; - esac - done - - shift $(($OPTIND - 1)) - - if [ $# -eq 0 ]; then - echo "Missing argument." - echo "Use $0 -h for help." - return 1 - fi - - _pacman_set_vars - eval "${CMD} $@ 2>/dev/null" | awk -F "$SEP" -v filter="$pacman_deps" '$0 ~ filter {gsub(/[>=<][^ ]*/,"",$2) ; gsub(/ +/,"\n",$2) ; print $2}' | sort -u - _pacman_unset_vars - } -fi - -fi - - ##============================================================================== ## TeXlive functions ##============================================================================== @@ -915,6 +624,8 @@ fi ## TeXlive if [ -d "/usr/local/texlive" ]; then + ## This function installs basic TeX and LaTeX packages. This is very + ## user-specific, so you should adapt the list to your needs. tlinit () { ## Warning: it is important to set umask properly, otherwise users might @@ -954,5 +665,4 @@ if [ -d "/usr/local/texlive" ]; then xcolor \ zapfding' } - fi diff --git a/.shell.d/keys_zsh b/.shell.d/keys_zsh index 8cc58709..cb7459eb 100644 --- a/.shell.d/keys_zsh +++ b/.shell.d/keys_zsh @@ -1,15 +1,11 @@ -## -*- mode:sh -*- # ################################################################################ ## Zsh Key bindings -## Date 2011-11-19 +## 2012-08-11 ################################################################################ - -##============================================================================== -## Zsh keys -##============================================================================== -# http://mundy.yazzy.org/unix/zsh.php -# http://www.zsh.org/mla/users/2000/msg00727.html +## References: +## http://mundy.yazzy.org/unix/zsh.php +## http://www.zsh.org/mla/users/2000/msg00727.html ## Bindings functions: # backward-char @@ -32,44 +28,43 @@ # up-line-or-search # expand-or-complete-prefix ## completion in the middle of a line -if isShell "zsh"; then - bindkey -e # Emacs bindings +## Emacs bindings +bindkey -e - ## Set '/' as a word delimiter. - autoload -U select-word-style - select-word-style bash +## Set '/' as a word delimiter. +autoload -U select-word-style +select-word-style bash - ## ??? - # typeset -g -A key +## ??? +# typeset -g -A key - ## Note that double brackets are needed to expand wildcards properly. - if [[ $TERM = *xterm* ]] ; then - bindkey "\e[3~" delete-char - bindkey "\e[1;5D" backward-word - bindkey "\e[1;5C" forward-word - bindkey "\eOH" beginning-of-line - bindkey "\eOF" end-of-line +## Note that double brackets are needed to expand wildcards properly. +if [[ $TERM = *xterm* ]] ; then + bindkey "\e[3~" delete-char + bindkey "\e[1;5D" backward-word + bindkey "\e[1;5C" forward-word + bindkey "\eOH" beginning-of-line + bindkey "\eOF" end-of-line - bindkey "\e[Z" reverse-menu-complete # Shift+Tab - fi + bindkey "\e[Z" reverse-menu-complete # Shift+Tab +fi - if [[ $TERM = *rxvt* ]] ; then - bindkey "\e[3~" delete-char - bindkey "\eOd" backward-word - bindkey "\eOc" forward-word - bindkey "\e[7~" beginning-of-line - bindkey "\e[8~" end-of-line +if [[ $TERM = *rxvt* ]] ; then + bindkey "\e[3~" delete-char + bindkey "\eOd" backward-word + bindkey "\eOc" forward-word + bindkey "\e[7~" beginning-of-line + bindkey "\e[8~" end-of-line - bindkey "\e[Z" reverse-menu-complete # Shift+Tab - fi + bindkey "\e[Z" reverse-menu-complete # Shift+Tab +fi ## For rxvt. - # bindkey "\e[7~" beginning-of-line # Home - # bindkey "\e[8~" end-of-line # End +# bindkey "\e[7~" beginning-of-line # Home +# bindkey "\e[8~" end-of-line # End ## For FreeBSD console. - # bindkey "\e[H" beginning-of-line - # bindkey "\e[F" end-of-line +# bindkey "\e[H" beginning-of-line +# bindkey "\e[F" end-of-line -fi diff --git a/.shell.d/main_rc b/.shell.d/main_rc index 29273154..fba01104 100644 --- a/.shell.d/main_rc +++ b/.shell.d/main_rc @@ -25,6 +25,11 @@ if [ -d "${TEXROOT}" ]; then unset TEXFOLDER fi +## Enable color support of ls. +if [ "$TERM" != "dumb" ]; then + eval "`dircolors -b`" +fi + ## Terminal ## WARNING: this is always a bad idea! # if [[ "$TERM" = "*rxvt*" ]]; then @@ -39,7 +44,7 @@ export MANPAGER="less -s" export MANWIDTH=80 ## Time display (with ls command for example) -export TIME_STYLE=+"| %d/%m/%Y %H:%M | " +export TIME_STYLE=+"| %d/%m/%Y %H:%M:%S | " ## System locale # export LC_MESSAGES=fr_FR.utf8 diff --git a/.shell.d/options_bash b/.shell.d/options_bash index 8fa08d22..1ddaca9f 100644 --- a/.shell.d/options_bash +++ b/.shell.d/options_bash @@ -3,161 +3,160 @@ ## Bash specific options ################################################################################ -if isShell "bash"; then - ## Enable programmable completion features (you don't need to enable ## this, if it's already enabled in /etc/bash.bashrc and /etc/profile ## sources /etc/bash.bashrc). - if [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi +[ -f /etc/bash_completion ] && . /etc/bash_completion ## Sudo completion - complete -cf sudo +complete -cf sudo - set +o nounset # Otherwise some completions will fail - set completion-ignore-case on - set show-all-if-ambiguous on +set +o nounset # Otherwise some completions will fail +set completion-ignore-case on +set show-all-if-ambiguous on ## Use TAB to switch between completions instead of waiting for the next character. #bind '"\t":menu-complete' - export FIGNORE=".o:~" # A list of suffixes to ignore when performing filename completion - set filec # To search and fill the complete name of a file (with ) - +## A list of suffixes to ignore when performing filename completion +export FIGNORE=".o:~" +## To search and fill the complete name of a file (with ) +set filec ##====================================================================== ## History management ##====================================================================== - export HISTCONTROL=ignoredups # don't put duplicate lines in the history. See bash(1) for more options - export HISTFILESIZE=1000 # Define number of previous commands stored - export HISTIGNORE="&:bg:fg:ll:h:ls:la:la:lk:clear:exit:history" - export HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S_%a " + +# Don't put duplicate lines in the history. See bash(1) for more options. +export HISTCONTROL=ignoredups + +# Define number of previous commands stored. +export HISTFILESIZE=1000 + +export HISTIGNORE="&:bg:fg:ll:h:ls:la:la:lk:clear:exit:history" +export HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S_%a " ##====================================================================== ## Various options ##====================================================================== - set -o notify # Jobs notify shell about their states immediately -#set ignoreeof # To avoid accidentally quitting the shell with - -#shopt -u mailwarn # Disable the shell ability to warn about incoming mail - shopt -s cdable_vars # if cd arg is not valid, assumes its a var defining a dir - shopt -s cdspell # To correct minor error in the directory spelling (during cd) - shopt -s checkhash - shopt -s checkwinsize # update the value of LINES and COLUMNS after each command if altered - shopt -s cmdhist # save multi-line commands in history as single line - shopt -s dirspell - shopt -s dotglob # include dotfiles in pathname expansion - shopt -s expand_aliases # expand aliases - shopt -s extglob # enable extended pattern-matching features - shopt -s histappend # append to (not overwrite) the history file - shopt -s hostcomplete # attempt hostname expansion when @ is at the beginning ofa word - shopt -s no_empty_cmd_completion # No completion on an empty line - shopt -s nocaseglob # pathname expansion will be treated as case-insensitive - shopt -s progcomp #To enable the programmable completion - +set -o notify # Jobs notify shell about their states immediately. +#set ignoreeof # To avoid accidentally quitting the shell with . +#shopt -u mailwarn # Disable the shell ability to warn about incoming mail. +shopt -s cdable_vars # If cd arg is not valid, assumes its a var defining a dir. +shopt -s cdspell # To correct minor error in the directory spelling (during cd). +shopt -s checkhash +shopt -s checkwinsize # Update the value of LINES and COLUMNS after each command if altered. +shopt -s cmdhist # Save multi-line commands in history as single line. +shopt -s dirspell +shopt -s dotglob # Include dotfiles in pathname expansion. +shopt -s expand_aliases # Expand aliases. +shopt -s extglob # Enable extended pattern-matching features. +shopt -s histappend # Append to (not overwrite) the history file. +shopt -s hostcomplete # Attempt hostname expansion when @ is at the beginning of a word. +shopt -s no_empty_cmd_completion # No completion on an empty line. +shopt -s nocaseglob # Pathname expansion will be treated as case-insensitive. +shopt -s progcomp # To enable the programmable completion. ##============================================================================== ## PS1 -- Full width bar with informations. ##============================================================================== + ## An external function is needed to update $COLUMNS value, as well as path, time, and other variables. - function PSBAR () - { - # Initialization. - BARCOLOR=$BBlue - OUTPUT="$BARCOLOR[" - SYMBOLVAR='=' - CENTERVAR=" $(date +%H:%M:%S) " +_psbar () +{ + ## Initialization. + BARCOLOR=$BBlue + OUTPUT="$BARCOLOR[" + SYMBOLVAR='=' + CENTERVAR=" $(date +%H:%M:%S) " - # Truncated path. - local PWDMAXLEN=$(($COLUMNS/2-${#CENTERVAR}/2-3)) # '3' stands for '[ $SYMBOLVAR'. - local TRUNC_SYMBOL="..." - if [[ $PWD == $HOME* ]]; then - newPWD="~${PWD#$HOME}" - else - newPWD=${PWD} - fi - if [ ${#newPWD} -gt $PWDMAXLEN ]; then - local PWDOFFSET=$(( ${#newPWD} - $PWDMAXLEN + ${#TRUNC_SYMBOL} )) - newPWD="${TRUNC_SYMBOL}${newPWD:$PWDOFFSET:$PWDMAXLEN}" - fi + ## Truncated path. + ## '3' stands for '[ $SYMBOLVAR'. + local PWDMAXLEN=$(($COLUMNS/2-${#CENTERVAR}/2-3)) + local TRUNC_SYMBOL="..." + if [[ $PWD == $HOME* ]]; then + newPWD="~${PWD#$HOME}" + else + newPWD=${PWD} + fi + if [ ${#newPWD} -gt $PWDMAXLEN ]; then + local PWDOFFSET=$(( ${#newPWD} - $PWDMAXLEN + ${#TRUNC_SYMBOL} )) + newPWD="${TRUNC_SYMBOL}${newPWD:$PWDOFFSET:$PWDMAXLEN}" + fi - # Truncated login information. - local LOGINFO="$(whoami)@$HOSTNAME" - if [ ${#LOGINFO} -gt $(($COLUMNS/2-${#CENTERVAR}/2-3)) ] # '3' stands for '$SYMBOLVAR ]' - then - LOGINFO=$USER - if [ ${#LOGINFO} -gt $(($COLUMNS/2-${#CENTERVAR}/2-3)) ] # '3' stands for '$SYMBOLVAR ]' - then - unset LOGINFO - fi - fi + ## Truncated login information. + local LOGINFO="$(whoami)@$HOSTNAME" + if [ ${#LOGINFO} -gt $(($COLUMNS/2-${#CENTERVAR}/2-3)) ] + then + LOGINFO=$USER + if [ ${#LOGINFO} -gt $(($COLUMNS/2-${#CENTERVAR}/2-3)) ] + then + unset LOGINFO + fi + fi - # Left and right side. Empty if terminal width is too small. - if [ $COLUMNS -gt 50 ] - then - LEFTSIDEVAR="$newPWD " - RIGHTSIDEVAR=" $LOGINFO" - fi + ## Left and right side. Empty if terminal width is too small. + if [ $COLUMNS -gt 50 ] + then + LEFTSIDEVAR="$newPWD " + RIGHTSIDEVAR=" $LOGINFO" + fi - # Left side. - OUTPUT="$OUTPUT$BPurple$LEFTSIDEVAR" + ## Left side. + OUTPUT="$OUTPUT$BPurple$LEFTSIDEVAR" - # Reset bar color - OUTPUT="$OUTPUT$BARCOLOR" + ## Reset bar color + OUTPUT="$OUTPUT$BARCOLOR" - # In case of odd values. - if [ $(($COLUMNS%2)) -eq 1 ] - then - OUTPUT="$OUTPUT$SYMBOLVAR" - fi + ## In case of odd values. + if [ $(($COLUMNS%2)) -eq 1 ] + then + OUTPUT="$OUTPUT$SYMBOLVAR" + fi - # Fill 'OUTPUT' variable with the desired chars. - for i in $( seq $(($COLUMNS/2-${#LEFTSIDEVAR}-${#CENTERVAR}/2-1)) ) # '1' stands for '[' - do - OUTPUT="$OUTPUT$SYMBOLVAR" - done + ## Fill 'OUTPUT' variable with the desired chars. + ## '1' stands for '[' + for i in $( seq $(($COLUMNS/2-${#LEFTSIDEVAR}-${#CENTERVAR}/2-1)) ) + do + OUTPUT="$OUTPUT$SYMBOLVAR" + done + ## Center. + OUTPUT="$OUTPUT$Color_Off$CENTERVAR" - # Center. - OUTPUT="$OUTPUT$Color_Off$CENTERVAR" + ## Reset bar color + OUTPUT="$OUTPUT$BARCOLOR" + ## Fill 'OUTPUT' variable with the desired chars. + for i in $( seq $(($COLUMNS/2-${#CENTERVAR}/2-${#RIGHTSIDEVAR}-1)) ) + do + OUTPUT="$OUTPUT$SYMBOLVAR" + done - # Reset bar color - OUTPUT="$OUTPUT$BARCOLOR" + ## Right side. + OUTPUT="$OUTPUT$BGreen$RIGHTSIDEVAR" - # Fill 'OUTPUT' variable with the desired chars. - for i in $( seq $(($COLUMNS/2-${#CENTERVAR}/2-${#RIGHTSIDEVAR}-1)) ) # '1' stands for ']' - do - OUTPUT="$OUTPUT$SYMBOLVAR" - done + ## Reset bar color + OUTPUT="$OUTPUT$BARCOLOR" + ## Close bar + OUTPUT="$OUTPUT]\n" - # Right side. - OUTPUT="$OUTPUT$BGreen$RIGHTSIDEVAR" + ## Prompt. + if [ $(id -u) -eq 0 ] + then + ## Root access + OUTPUT="$OUTPUT$BRed# $Color_Off" + else + ## Normal user + OUTPUT="$OUTPUT$BYellow$ $Color_Off" + fi - # Reset bar color - OUTPUT="$OUTPUT$BARCOLOR" - - # Close bar - OUTPUT="$OUTPUT]\n" - - - # Prompt. - if [ $(id -u) -eq 0 ] - then - # Root access - OUTPUT="$OUTPUT$BRed# $Color_Off" - else - # Normal user - OUTPUT="$OUTPUT$BYellow$ $Color_Off" - fi - - # Set result to PS1. - PS1="$OUTPUT" - } + ## Set result to PS1. + PS1="$OUTPUT" +} ##============================================================================== @@ -169,10 +168,9 @@ if isShell "bash"; then ## PS1 ##============================================================================== -## PS1 using PSBAR function. -#PROMPT_COMMAND='PSBAR' +## PS1 using _psbar function. +#PROMPT_COMMAND='_psbar' ## Simple PS1 - PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] ' +PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] ' -fi diff --git a/.shell.d/options_zsh b/.shell.d/options_zsh index b8761ddd..e3e74343 100644 --- a/.shell.d/options_zsh +++ b/.shell.d/options_zsh @@ -4,102 +4,99 @@ ## Date 2011-11-19 ################################################################################ - -if isShell "zsh"; then - ##============================================================================== ## History options ##============================================================================== - HISTFILE=~/.zshistfile - HISTSIZE=1000 - SAVEHIST=1000 - setopt hist_ignore_all_dups - setopt hist_ignore_space # Commands beginning with a space won't be recorded. - setopt appendhistory +HISTFILE=~/.zshistfile +HISTSIZE=1000 +SAVEHIST=1000 +setopt hist_ignore_all_dups +setopt hist_ignore_space # Commands beginning with a space won't be recorded. +setopt appendhistory ##============================================================================== -## Various +## Misc ##============================================================================== - # setopt completealiases # Not recommended. - setopt autocd # When only dirname is entered, then auto cd to it. - # setopt extendedglob nomatch notify # ??? - unsetopt beep # ??? +## Not recommended. +# setopt completealiases + +setopt autocd # When only dirname is entered, then auto cd to it. + +## ??? +# setopt extendedglob nomatch notify + +## Usually not needed if pc speaker is off. +unsetopt beep ##============================================================================== ## VCS ##============================================================================== -## TODO: work on it... +## TODO: to be continued... # autoload -Uz vcs_info zstyle ':vcs_info:*' enable git hg svn # autoload -Uz vcs_info ##============================================================================== -## Dir stack +## Directory stack ##============================================================================== - DIRSTACKSIZE=20 +DIRSTACKSIZE=20 - setopt autopushd pushdsilent pushdtohome - setopt pushdignoredups - # setopt pushdminus ## This revert the +/- operators. +setopt autopushd pushdsilent pushdtohome +setopt pushdignoredups - alias dh='dirs -v' +## This revert the +/- operators. +# setopt pushdminus - if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]]; then - dirstack=( $(< ~/.zdirs) ) - popd > /dev/null - fi - precmd() { - dirs -l >! ~/.zdirs - } +alias dh='dirs -v' + +if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]]; then + dirstack=( $(< ~/.zdirs) ) + popd > /dev/null +fi +precmd() { + dirs -l >! ~/.zdirs +} ##============================================================================== ## ??? ##============================================================================== - zstyle :compinstall filename "$HOME/.zshrc" - +zstyle :compinstall filename "$HOME/.zshrc" ##============================================================================== ## Completion ##============================================================================== - autoload -Uz compinit - compinit +autoload -Uz compinit +compinit - zstyle ':completion:*' menu select - zstyle ':completion:*:descriptions' format '%U%B%d%b%u' - zstyle ':completion:*:commands' rehash true # New binaries in path get recognized. +zstyle ':completion:*' menu select +zstyle ':completion:*:descriptions' format '%U%B%d%b%u' +zstyle ':completion:*:commands' rehash true # New binaries in path get recognized. - zstyle ':completion:*' completer _complete _match _approximate ## Allow approximate - zstyle ':completion:*:match:*' original only - zstyle ':completion:*:approximate:*' max-errors 1 numeric +zstyle ':completion:*' completer _complete _match _approximate ## Allow approximate +zstyle ':completion:*:match:*' original only +zstyle ':completion:*:approximate:*' max-errors 1 numeric ## Tab completion for PID :D -- Useless ? - # zstyle ':completion:*:*:kill:*' menu yes select - # zstyle ':completion:*:kill:*' force-list always +# zstyle ':completion:*:*:kill:*' menu yes select +# zstyle ':completion:*:kill:*' force-list always ##============================================================================== ## TESTING ##============================================================================== -# Remove RPS1 after - setopt transient_rprompt +## Remove RPS1 after +setopt transient_rprompt -# Color vars - autoload -U colors terminfo - colors - -# Zargs pawa - autoload -U zargs +## Color vars +autoload -U colors terminfo +colors + +## Zargs powaa +autoload -U zargs ##============================================================================== ## Prompt ##============================================================================== - autoload -U promptinit - promptinit - prompt adam2 - -##============================================================================== -## Colors for dirs. -##============================================================================== - eval `dircolors -b` - -fi +autoload -U promptinit +promptinit +prompt adam2 diff --git a/.zshrc b/.zshrc index c155983b..e5d035a2 100644 --- a/.zshrc +++ b/.zshrc @@ -1,6 +1,6 @@ ################################################################################ ## Shell Config -- Master File -## Date 2012-07-02 +## Date 2012-08-11 ################################################################################ ##============================================================================== @@ -9,32 +9,21 @@ ## Useless for Zsh ? [ -z "$PS1" ] && return - -##============================================================================== -## Base functions -##============================================================================== - -isShell() -{ - if [ "$1" = "$(ps | grep $$ | awk '{print $4}')" ]; then - return 0 - else - return 1 - fi -} - ##============================================================================== ## Sourcing ##============================================================================== -SHELLDIR="$HOME/.shell.d" +SHELL_CURRENT="$(ps | awk -v shellpid=$$ '$0 ~ shellpid {print $4}')" +SHELL_DIR="$HOME/.shell.d" -source "${SHELLDIR}/main_rc" # Should be sourced first. -source "${SHELLDIR}/options_zsh" # Should be sourced first. -source "${SHELLDIR}/colors_rc" # Should be sourced first. +## Should be sourced first. +source "${SHELL_DIR}/main_rc" +source "${SHELL_DIR}/options_zsh" -source "${SHELLDIR}/funs_rc" -source "${SHELLDIR}/alias_rc" -source "${SHELLDIR}/keys_zsh" -source "${SHELLDIR}/personal_rc" +## Source order should not matter. +source "${SHELL_DIR}/alias_rc" +source "${SHELL_DIR}/colors_zsh" +source "${SHELL_DIR}/funs_rc" +source "${SHELL_DIR}/keys_zsh" +source "${SHELL_DIR}/personal_rc"