From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7766 invoked from network); 21 Jul 2005 22:20:26 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 21 Jul 2005 22:20:26 -0000 Received: (qmail 52516 invoked from network); 21 Jul 2005 22:20:17 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Jul 2005 22:20:17 -0000 Received: (qmail 21211 invoked by alias); 21 Jul 2005 22:20:08 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9122 Received: (qmail 21200 invoked from network); 21 Jul 2005 22:20:07 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 21 Jul 2005 22:20:07 -0000 Received: (qmail 51501 invoked from network); 21 Jul 2005 22:20:07 -0000 Received: from ns.pcdesk.net (HELO pcdesk.net) (65.100.173.137) by a.mx.sunsite.dk with SMTP; 21 Jul 2005 22:20:03 -0000 Received: from localhost ([::ffff:24.86.115.190]) (AUTH: LOGIN tspivey@pcdesk.net) by pcdesk.net with esmtp; Thu, 21 Jul 2005 16:19:56 -0600 id 01C031FA.42E01F8C.000012BF Date: Thu, 21 Jul 2005 15:20:24 -0700 From: Tyler Spivey To: zsh-users@sunsite.dk Subject: Help with paths and file sorting Message-ID: <20050721222024.GA14060@fast.vc.shawcable.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline User-Agent: Mutt/1.5.8i X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 1. is there an easy way to take a filespec like: /home/tyler/dir1/* and go back a directory? so the spec is /home/tyler/*? 2. is there a way of, once having an array of files obtained by the * globbing operator, to sort them by size, time, etc? I'm asking this because I'm writing a file manager - here it is below, since in its infancy it's quite small. I'm hoping that I won't have to move to another language like python - even though I like python - but shell seems more appropriate. #!/bin/zsh zmodload zsh/stat #this is a zsh file manager. #variables. typeset -A keys keys=( e editspec g go p previous n next q exit s size " " printfile ) function editspec { vared -p "filespec: " fs readfiles cur=1 printfile } ## grab a key, and send it off to the handler. for the main loop. function grabkey { read -sk1 key handle $key } ## main key handler. decide just what to do with this key. function handle { if [[ -z $keys[$1] ]]; then echo "key undefined." return fi $keys[$1] } ##print current file. function printfile { echo ${files[$cur]:t} } ## next/previous file. function next { len=${#files} # handle empty dir. if [[ $len -lt 1 ]];then echo "empty dir." return fi cur+=1 if [[ $cur -gt $len ]];then echo "end" cur=$len fi printfile } function previous { len=${#files} # handle empty dir. if [[ $len -lt 1 ]];then echo "empty dir." return fi cur+=-1 if [[ $cur -lt 1 ]];then echo "beginning" cur=1 fi printfile } function size { echo `stat +size $files[$cur]` } function getspec { echo "filespec:" read fs if [[ -z $fs ]];then fs=\* fi } function readfiles { echo -n "reading files..." files=($~fs) echo "done, ${#files} files." } ## refresh the file list. function go { pth=${fs:h}/${files[$cur]:t} if [[ -d $pth ]];then fs=$pth/* echo $fs readfiles cur=1 printfile return fi echo "not a dir" } getspec readfiles typeset -i cur=1 printfile while :;do grabkey done