Commits

lan Nomar committed cb9b3ff

added tools/organizer.brc # unfinished
will look at a mime or extension and move it to a directory you've selected
changed parse/tagmarks.brc # unfinished, probably broken/unusable
changed net/ftpcp.brc | finished

  • Participants
  • Parent commits 536a95e

Comments (0)

Files changed (3)

 #!/bin/brc
-	
+
+# TODO: escape weird chars, will break if a multi-\n file is found
+#	But who is crazy enough to try that (except for me)
+
+# Needed: vchop
+# { . `{ module.brc chop }	}
+
+fn expr { builtin expr $* > /dev/null }
+
 { . $HOME/.config/brc/modules/std }
 
-#contains (
-# errors on mput because its not a plain file
-# nl 
-user = nmz
-pass = DancingMad
-host = 10.0.0.66
+fn debug { echo $* }
+fn debug {}
 
-rootpath = Music
+type = binary
 
-url = ( ftp://$user:$pass@$host/$rootpath/ )
-
-fn ls { builtin ls -F $* }
-
-fn seelist { echo $1 ; shift ; for ( * in $* ) { echo '	' $* } }
-fn old {
-	ifs='' { identify `{pwd} }
-	pwd
-	seelist files $files
-	seelist dirs $dirs
-	
-
-fn send {
-	cd $^*
-	# set files dirs
-	for (* in `` $nl { ls | grep -v '/' }){
-		type
-}	}
-	
-
-
-
-fn goback { # echoes cd ../../../
-	echo -n cd "
-	for ( * in `{ seq 0 $* } ) {
-		echo -n ../
-	}
-	echo "
+fn sendfile {
+ *=$* {  # ascii or binary?
+  if ( ~ `{ file -b $^* } *text* ) {
+	* = ascii } else { * = binary }
+	~ $type $* || { type = $* ; echo $type }
+ }
+ # send files
+  echo -n put "^$^*^" "
+  ifs=/ {
+	*=`{ echo -n $* }
+  }
+  echo $$#*^"
 }
 
-  # some vars that should exist at start time
-	pwd = `` (/) { echo -n $PWD }
+fn send { echo mput '*' $^nl^a } # errrs but works
+fn send {
+ for ( * in `` $ifs(3) { find $^* -type f -maxdepth 1 } ) {
+  sendfile $^*	
+}}
+
+fn magic {
+ if ( ! ~ $#ld 0 ) {
+  debug analyze: $#fd $#ld
+   ld=$ld fd=$fd {
+	vchop fd 1
+	vchop ld 1
+	* = ($^fd $^ld $fd($#fd))
+   }
+  if ( ~ $1 $2 ) { # dir -1 == cdir
+	echo cd ../
+   } else {
+   
+  # current dir is bigger than last one
+	# expr $#fd '>' $#ld && echo more || echo less
 	
-echo mkdir ftpcp/
-echo cd ftpcp/
+	if ( expr $#fd '<' $#ld ) { # go back 
+	# loop cd .. till $CWD matches $ld
+	fd=$fd {
+	 vchop fd 1
+	 echo -n cd "
+	 while ( ! ~ $^ld $^fd ) {
+		echo -n ../
+		vchop ld 1
+	 }
+	 echo "
+ }}}}
+	ld = $fd
+}
 	
-for (* in `` $nl { find $PWD -type d } ) {
+fn directory {
+
+	DIR = `` $ifs(3){ realpath $^*	}
+	
+ for ( * in `` $nl { find $^DIR -type d } ) {
+ 
   # Full directory
-	FD = $*
-	fd	= `` (/) { echo -n $* }
+   FD = $*
+   fd = `` (/) { echo -n $* }
+   
+   # keeps structure, cd's back if needed
+	magic $*
 	
-  # Current directory
-	fd = $fd { vshift fd $#pwd
-		cd = $fd }
-		
-	
-# stay in current directory
-  if ( ~ $#cd $#ld ) {
-		echo cd ../
-  } else {
-	if ( expr $#cd '<' $#ld > /dev/null ){
-		* = `{ expr $#ld '-' $#cd }
-		goback $*
-  } }
-  
-  # code starts
 	echo mkdir "$fd($#fd)^"
 	echo cd "$fd($#fd)^" 
 	echo lcd "$^FD^"
 	
-	# test all files, change type -- use function
-	echo mput '*' $^nl^a
-	
-	ld = $cd
+	send $*
+}}
+
+
+for (* in $*) {
+ if ( test -d $^* ) {
+  PWD=$PWD {
+	directory $^* }
+  cd $PWD
+ } else {
+  sendfile $^*
+ }
 }
 
+echo bye

parse/tagmarks.brc

 #!/usr/bin/env brc
 
+fn OLD {
 # This depends hugely on a tag file
 #Tag files usually go by [TAG] in a line by itself
 # then links follow, thebecause links are only one field, everything else is a tag, so they get appended towards the end of the line
 	case *					;	file=$file/URLMark
 }
 
-for (* in `` ($nl) { cat $file } ) {
-	*=`{ echo -n $* }
+
+if ( ! ~ $#Tag 0 ) {
+	echo BUG, $#Tag items found dangling
+	echo $Tag
+}
+
+#for (* in `{ seq 10 } ) { echo }
+	  #if (~ $#Link 0) {			*=($* $Tag)
+#		if (~ $* $Links) {
+#			for (* in $Links) {		# * = EXCLUDE
+#				count=($* $count)
+#			  ~ $* $Links && { *=$#count ; break }
+#			}	}
+#			Drop $*
+#	cases ']'^*^'[' '['* ']'* *']' **'['
+
+#file save and all that shit
+#and tr -s  [] "
+}
+
+fn newsbeuter {
+ # Converts tagmarks to the newsbeuter urls feed
+ tofile = $HOME/.config/urls
+ infile = $*
+	
+ for ( * in `` ($ifs(3)) { cat $* } ) {
+  *=`{ echo -n $* }
   switch ( $^* ) {
-	case '['^*^']'
+	case '['^*^']'	# Its a tag!
 		*=`` ('[' ']') { echo -n $* }
 
 		if (~ $^* $Tag(1)) {
-		#( DEBUG )#
-		~ $DEBUG 1 && echo '---	getting rid of' $^* '	---'
+		echo '---	getting rid of' $^* '	---'
 			vshift Tag
 		  } else {
 		~ $DEBUG 1 && echo '---	adding' $^*'	---'
 
   echo $*
 }
-
-
-
-
-
-
-
-if ( ! ~ $#Tag 0 ) {
-	echo BUG, $#Tag items found dangling
-	echo $Tag
+	
 }
 
-#for (* in `{ seq 10 } ) { echo }
-	  #if (~ $#Link 0) {			*=($* $Tag)
-#		if (~ $* $Links) {
-#			for (* in $Links) {		# * = EXCLUDE
-#				count=($* $count)
-#			  ~ $* $Links && { *=$#count ; break }
-#			}	}
-#			Drop $*
-#	cases ']'^*^'[' '['* ']'* *']' **'['
-
-#file save and all that shit
-#and tr -s  [] "
+$*

tools/organizer.brc

+#!/bin/brc
+
+if ( ~ $1 - ) {
+	flags = $1
+	shift
+}
+
+fn whichdir {
+ ifs=. {
+	* = `{ echo -n $^* }
+ }
+ switch ( $$#* ) {
+  case flv avi	; * = $HOME/Hideo/misc	# Video files
+  case mp3		; * = $HOME/Audio/misc	# Audio
+  case pdf		; * = $HOME/Docs/Misc
+  case torrent	; * = $HOME/Downloads/torrents
+  case fs		; * = $HOME/Oven/lang/forth/samples
+  case c h 		; * = $HOME/Oven/lang/C/misc/
+  case *		; * = ()
+ }
+ dir = $^*
+}
+
+
+for ( * in $* ) {
+ if ( test -d $* ) {
+	cd $^*
+	shift
+ }
+
+ if ( ~ $#* 0 ) {
+	* = ./*
+ }
+ 
+ for ( * in $* ) {
+	whichdir $^*
+  if ( ! ~ $#dir 0 ) {
+	mv -v $flags $^* $^dir
+}}}
+