# v0.4 function for .bashrc/.kshrc function el { [ "$el" ] && { if [ -d $el ]; then cd $el ; else export el=; fi } case $1 in -a)o=A; shift;; -e)[ "$el" ] && cd - >/dev/null; export el=$2;return;; -h)echo "find/edit files in basedir matching all args" echo "use: el [-a|-e |-g|-h|-z] [search terms]" echo " -a include hidden files" echo " -e set \$el" echo " -h help" echo " -g go to \$el ($el)" echo " -z show basedir (\$el, defaults to current dir if unset)" return ;; -g)return;; -z)echo ${el:-$(pwd)}; [ "$el" ] && cd - >/dev/null; return;; esac [ $1 ] || { ls -p$o; [ "$el" ] && cd - >/dev/null; return } eval $(ls -p$o | awk -v z="$*" ' BEGIN { split(z,a," ") } { t=1 for( x in a ) if( $0 !~ a[x] ) t=0 if( t ) { if( $0 !~ /\/$/ ) b[++i] = $0 c[++j] = $0 } } END { if( i == 1 ) { print "$EDITOR \"" b[1] "\"; [ \"$el\" ] && cd - >/dev/null; return;" } else for(k=1;k<=j;k++) print "j[" k "]=\"" c[k] "\";" }') echo " 0) $*" while [[ $i -lt ${#j[@]} ]];do i=$(($i+1));echo " $i) ${j[$i]}";done read -e -p " $el$ " if [ "$REPLY" == "0" ];then $EDITOR "$*" elif [ "$(echo $REPLY | awk '/^[1-9]/')" ] && [ "${j[$REPLY]}" ];then $EDITOR "${j[$REPLY]}" elif [ ${#REPLY} -ne 0 ]; then $EDITOR "$REPLY" fi unset i j [ "$el" ] && cd - >/dev/null }