From b3c9a9c6e9bd1baf28dcb76cb347cf8f589bbd12 Mon Sep 17 00:00:00 2001 From: David Alexander Majnemer Date: Sat, 3 Jan 2009 14:15:00 -0600 Subject: [PATCH] - fixed a bug here and there - made it fully sh compliant (works even with solaris sh) --- commonsh/01_ports | 16 +++++++++------- commonsh/02_term | 32 ++++++++++++++++++++++---------- commonsh/10_alias | 22 ++++++++++++---------- commonsh/10_git | 14 ++++++++------ commonsh/10_pager | 11 ++++++----- commonsh/10_rlwrap | 3 ++- commonsh/10_utility | 21 ++++++++++----------- lessfilter | 2 +- 8 files changed, 70 insertions(+), 51 deletions(-) diff --git a/commonsh/01_ports b/commonsh/01_ports index bd443dd..d7ca964 100755 --- a/commonsh/01_ports +++ b/commonsh/01_ports @@ -1,25 +1,27 @@ -if [[ -d /opt/local/man ]] ; then - if [[ -z "${MANPATH}" ]] ; then - MANPATH="/opt/local/man":$(manpath) +#! /bin/sh + +if [ -d /opt/local/man ] ; then + if [ -z "${MANPATH}" ] ; then + MANPATH="/opt/local/man":`manpath` else MANPATH="/opt/local/man:${MANPATH}" fi export MANPATH fi -if [[ -d /opt/local/bin ]] ; then - if [[ -z "${PATH}" ]] ; then +if [ -d /opt/local/bin ] ; then + if [ -z "${PATH}" ] ; then PATH="/opt/local/bin" else PATH="/opt/local/bin:${PATH}" fi fi -if [[ -d /opt/local/sbin ]] ; then +if [ -d /opt/local/sbin ] ; then PATH="/opt/local/sbin:${PATH}" fi -if [[ -d /opt/local/libexec ]] ; then +if [ -d /opt/local/libexec ] ; then PATH="/opt/local/libexec:${PATH}" fi diff --git a/commonsh/02_term b/commonsh/02_term index ef28517..df6ed0c 100755 --- a/commonsh/02_term +++ b/commonsh/02_term @@ -1,7 +1,9 @@ +#! /bin/sh + # terminal fallback stuff -function fix_term () +fix_term () { - if (infocmp $1 &> /dev/null) ; then + if (infocmp $1 > /dev/null 2>&1) ; then echo $1 else case $1 in @@ -28,12 +30,14 @@ function fix_term () } # sorta hacky, but I cannot find a better way to do this :/ -function fix_terminfo_db () +fix_terminfo_db () { - if [[ `type -p infocmp` = "$1/bin/infocmp" ]] ; then - export TERMINFO="$1/share/terminfo" + if [ `command -v infocmp` = "$1/bin/infocmp" ] ; then + TERMINFO="$1/share/terminfo" + export TERMINFO fi } + # terminal surgery case `uname -s` in Interix) @@ -42,11 +46,19 @@ case `uname -s` in SunOS) fix_terminfo_db "/opt/csw" ;; + Darwin) + fix_terminfo_db "/opt/local" + ;; esac -export TERM=$(fix_term $TERM) - -if [[ $TERM == *256* ]] && (infocmp screen-256color-bce &> /dev/null) ; then - export SCREEN_COLOR="-256color" -fi +TERM=`fix_term $TERM` +export TERM +case $TERM in + *256*) + if (infocmp screen-256color-bce > /dev/null 2>&1) ; then + SCREEN_COLOR="-256color" + export SCREEN_COLOR + fi + ;; +esac diff --git a/commonsh/10_alias b/commonsh/10_alias index 5bdc09e..7915526 100755 --- a/commonsh/10_alias +++ b/commonsh/10_alias @@ -1,15 +1,16 @@ +#! /bin/sh # colors for dircolors in gdircolors dircolors ; do - if (type -p $dircolors &> /dev/null) ; then - [ -f /etc/DIR_COLORS ] && eval $($dircolors -b /etc/DIR_COLORS) && break - [ -f "${HOME}/.dir_colors" ] && eval $($dircolors -b "${HOME}/.dir_colors") && break - eval $($dircolors -b) && break + if (command -v $dircolors > /dev/null 2>&1) ; then + [ -f /etc/DIR_COLORS ] && eval `$dircolors -b /etc/DIR_COLORS` && break + [ -f "${HOME}/.dir_colors" ] && eval `$dircolors -b "${HOME}/.dir_colors"` && break + eval `$dircolors -b` && break fi done # gimmie an editor, make it a nice vi clone for EDITOR in vim elvis vile nvi vi ; do - (type -p $EDITOR &> /dev/null) && break + (command -v $EDITOR > /dev/null 2>&1) && break done export EDITOR @@ -23,7 +24,8 @@ case `uname -s` in alias grep='grep -d skip --color=auto' ;; FreeBSD|Darwin|DragonFly) - export LSCOLORS=ExGxFxDxCxDxDxHbaDacec + LSCOLORS=ExGxFxDxCxDxDxHbaDacec + export LSCOLORS alias ls="ls -Gh" alias grep='grep -d skip --color=auto' ;; @@ -31,18 +33,18 @@ case `uname -s` in alias ls="ls --color" ;; SunOS) - if (type -p gls &> /dev/null) ; then + if (command -v gls > /dev/null 2>&1) ; then alias ls="gls -h --color=auto" else alias ls="ls -h" fi - if (type -p ggrep &> /dev/null) ; then + if (command -v ggrep > /dev/null 2>&1) ; then alias grep='ggrep -d skip --color=auto' fi for locate in glocate slocate ; do - (type -p $locate &> /dev/null) && alias locate=$locate + (command -v $locate > /dev/null 2>&1) && alias locate=$locate done ;; esac @@ -52,4 +54,4 @@ alias du='du -h' alias ping='ping -c4' -(type -p time &> /dev/null) && alias time='command time' +(command -v time > /dev/null 2>&1) && alias time='command time' diff --git a/commonsh/10_git b/commonsh/10_git index 12e0d87..2bad1c5 100755 --- a/commonsh/10_git +++ b/commonsh/10_git @@ -1,21 +1,23 @@ -if [[ -d /usr/local/git/man ]] ; then - if [[ -z "${MANPATH}" ]] ; then - MANPATH="/usr/local/git/man":$(manpath) +#! /bin/sh + +if [ -d /usr/local/git/man ] ; then + if [ -z "${MANPATH}" ] ; then + MANPATH="/usr/local/git/man":`manpath` else MANPATH="/usr/local/git/man:${MANPATH}" fi export MANPATH fi -if [[ -d /usr/local/git/bin ]] ; then - if [[ -z "${PATH}" ]] ; then +if [ -d /usr/local/git/bin ] ; then + if [ -z "${PATH}" ] ; then PATH="/usr/local/git/bin" else PATH="/usr/local/git/bin:${PATH}" fi fi -if [[ -d /usr/local/git/libexec/git-core ]] ; then +if [ -d /usr/local/git/libexec/git-core ] ; then PATH="/usr/local/git/libexec/git-core:${PATH}" fi diff --git a/commonsh/10_pager b/commonsh/10_pager index 8f38326..b2ba957 100755 --- a/commonsh/10_pager +++ b/commonsh/10_pager @@ -1,17 +1,18 @@ for PAGER in less more pg ; do - (type -p $PAGER &> /dev/null) && break + (command -v $PAGER > /dev/null 2>&1) && break done export PAGER # if we are in less, we can set some options and use lesspipe -if [[ $PAGER = "less" ]] ; then +if [ $PAGER = less ] ; then # lesspipe can go by either lesspipe or lesspipe.sh for lesspipe in lesspipe lesspipe.sh ; do - if (type -p $lesspipe &> /dev/null) ; then - eval $(SHELL=/bin/sh $lesspipe) && break + if (command -v $lesspipe > /dev/null 2>&1) ; then + eval `SHELL=/bin/sh $lesspipe` && break fi done # let less be case insensitive - export LESS='-i -R -M' + LESS='-R -M' + export LESS fi diff --git a/commonsh/10_rlwrap b/commonsh/10_rlwrap index 5adb507..7627bac 100755 --- a/commonsh/10_rlwrap +++ b/commonsh/10_rlwrap @@ -1,3 +1,4 @@ +#! /bin/sh for wrap in rlwrap rlfe cle ; do - (type -p $wrap &> /dev/null) && alias ocaml="$wrap ocaml" && break + (command -v $wrap > /dev/null 2>&1) && alias ocaml="$wrap ocaml" && break done diff --git a/commonsh/10_utility b/commonsh/10_utility index 7455b1f..faa5942 100755 --- a/commonsh/10_utility +++ b/commonsh/10_utility @@ -1,15 +1,16 @@ +#! /bin/sh # utility.sh # Miscellaneous Utility Functions -function unkey-host () +unkey_host () { [ ${#} -ne 1 ] && return 1 sed -i -e "/$1/d" $HOME/.ssh/known_hosts } -function mkcd () +mkcd () { - if [[ -d "$1" ]] ; then + if [ -d "$1" ] ; then cd "$1" return fi @@ -17,16 +18,14 @@ function mkcd () mkdir -p "$1" && cd "$1" } -function extract () +extract () { - if [[ ! -f "$1" ]] ; then + if [ ! -f "$1" ] ; then echo "The file ("$1") does not exist!" return fi - local filename - - filename=$(echo "$1" | tr '[:upper:]' '[:lower:]') + filename=`echo "$1" | tr '[:upper:]' '[:lower:]'` case "$filename" in *.tar) @@ -42,10 +41,10 @@ function extract () unzip -qo "${1}" ;; *.gz|*.z) - gzip -dc "${1}" > $(basename "${1%.*}") + gzip -dc "${1}" > `basename "${1%.*}"` ;; *.bz2) - bzip2 -dc "${1}" > $(basename "${1%.*}") + bzip2 -dc "${1}" > `basename "${1%.*}"` ;; *.rar) unrar x -idq "${1}" @@ -60,7 +59,7 @@ function extract () lzma -dc "${1}" | tar xf ;; *.lzma) - lzma -dc "${1}" > $(basename "${1%.*}") + lzma -dc "${1}" > `basename "${1%.*}"` ;; *) echo "Unable to extract '"$1"'" diff --git a/lessfilter b/lessfilter index 3458743..08b6b51 100755 --- a/lessfilter +++ b/lessfilter @@ -1,4 +1,4 @@ -#!/bin/sh +#! /bin/sh # Decode file for less case `echo "$1" | tr '[:upper:]' '[:lower:]'` in # we don't handle archives, we let the big guy do it