Un outil pour réarranger les lignes de stdin - retour accueil
git clone git://bebou.netlib.re/reorder
Log | Files | Refs | README |
reorder (1191B)
1 #! /bin/sh 2 3 reset() { 4 sed -i "s/\[91m//g;s/\[92m//g;s/\[0m//g" $file 5 } 6 7 swaplines() { 8 paste -s | 9 awk "BEGIN{OFS=\"\n\"}{a=\$$1;\$$1=\$$2;\$$2=a}1" 10 } 11 12 modify() { 13 tput cup 0 0 14 printf "\033c" 15 case "$mode" in 16 (Looking) 17 cat $file | 18 sed "$1 s/^/\x1b[91m/;s/$/\x1b[0m/" ;; 19 (Selecting) 20 cat $file | 21 swaplines $1 $2 | 22 tee $file;; 23 (*) 24 break ;; 25 esac 26 } 27 28 clear 29 30 file="/tmp/a" 31 cat > $file 32 33 curline="1" 34 prevline="1" 35 lastline=$(< $file wc -l) 36 mode="Looking" 37 modify $curline $prevline 38 39 40 xev | 41 stdbuf -o0 grep "KeyPress" -A2 | 42 stdbuf -o0 grep -Eo "(Up|Down|Return|Escape)" | 43 while read key;do 44 case "$key" in 45 (Up) 46 [ $curline = "1" ] && continue 47 prevline=$curline; 48 curline=$(( $curline - 1 )) ;; 49 (Down) 50 [ $curline = $lastline ] && continue 51 prevline=$curline 52 curline=$(( $curline + 1 )) ;; 53 (Return) 54 prevline=$curline 55 reset 56 [ "$mode" = "Looking" ] \ 57 && { mode="Selecting"; 58 sed -Ei "$curline s/^/\x1b[92m/ 59 $curline s/$/\x1b[0m/" $file; } \ 60 || mode="Looking" ;; 61 (*) echo $key;exit 0 ;; 62 esac 63 modify $curline $prevline 64 echo $key 65 echo "Pour sortir appuyer plusieurs fois sur echap" 66 done