Plugin for nnn file manager, to only delete files from the last-selected directory. Written in Haxe. Current version relies on the `rm` unix utility... probably would be faster if all written in Haxe.




  

class NnnDeletePwdOnly {
static public function main():Void {

var content:String = sys.io.File.getContent('/home/brett/.config/nnn/.selection');

if (content.length == 0) {
  Sys.println(" selection file does not exist .. have you selected anything?");
  Sys.command("clear");
  Sys.exit(0);
} 

var result:Array = content.split("\u{0}"); 
var lastDir = haxe.io.Path.directory(result[result.length -1]);
Sys.println("Last dir selected is:" + lastDir); 

Sys.println(result.length); 
var k = 0;

while (k < result.length) {
  var forThisLoop = haxe.io.Path.directory(result[k]);
  if (lastDir == forThisLoop) {
    var hasToGo:String = result[k];
      Sys.println(" removing: " + hasToGo ); 
    final commandString = 'rm -rf $hasToGo';
    final process = new sys.io.Process(commandString);
    process.close();
  } else {
    var keeping = result[k];
      Sys.println(" NOT removing: " + keeping ); 
  }
k++;
}

Sys.command("clear");

}
}