Page 3 of 3

Posted: Tue 19 Nov 2013, 17:50
by amigo
@techno HeHe, I saw this: 'If you think this is appalling, check out BashTrix' in the sort thread. Hopefully the sort offered there is better than my proof-of-concept... It might compare favorably to the slim 'sort' in the thread if cut down to a similar size. All those things in BashTrix are necessarily long beacuse of handling some of the normal command-line options. And they are still longer because I coded them so they *might* be easier to read.

As for the thread about readlink, the suggested script is using readlink. I was asking about implementing readlink itself in shell.

Posted: Tue 19 Nov 2013, 19:42
by technosaurus
The dialog/Xdialog/whiptail/kdialog interface is pretty well standardized (though, could use a few patches to make them more compatible). I could write a matching espeak/sphinx voice-dialog wrapper that can be used as a fairly straightforward template for other backends like yad or gtkdialog.

Edit: to make readlink a "builtin", just edit http://git.busybox.net/busybox/tree/inc ... lets.src.h accordingly

@Amigo - I think Bashtrix is great btw... Just figured that anyone who thought my little sort function was abysmal would be overwhelmed by Bashtrix.

Posted: Wed 20 Nov 2013, 02:09
by technosaurus

Code: Select all

sortline(){
for x in $@;do
    [ ! "$FIRST" ] && FIRST=t && set --
    i=0
    while [ $i -le $# ];do
        [ $x -lt $((${@:$((i+1)):1})) ] && break || i=$((i+1))
    done
    set -- ${@:1:$i}  $x   ${@:$((i+1)):$(($#-$i))}
done
echo $@
}

Posted: Wed 20 Nov 2013, 08:45
by amigo
This should fix the spaces-in-names problem for dir_tree:

Code: Select all

#!/bin/sh
DIR=$1
[ $2 ] && SPACING=$2 || SPACING="|"
for x in * ; do
[ -d "$DIR/$x" ] &&  echo "$SPACING\`-{"$x && $0 $DIR/$x "$SPACING  "
done
And this:
"'for' splits the input by line"
is not correct. 'for' splits according to the IFS, which by default is 'space tab end-of-line'. I know the comments are old, but felt it would be good to correct it -for posterity...

techno, Can you explain what FIRST is?

Posted: Wed 20 Nov 2013, 14:27
by technosaurus
FIRST is poorly named, it should be something like ARGS_RESET

Code: Select all

[ ! "$FIRST" ] && FIRST=t && set -- 
resets $@ to "" on the first iteration (note that this is after the original $@ has been passed to the for loop), on subsequent runs $@ is modified by inserting the current iteration's value into $@ at the sorted location.