Since you don't want to dive into macros and you don't need anything 
super-generic, I think you're better off with @Benjaminel's idea: 
    
    
    template withcd(newdir: string, statements: untyped) =
      let olddir = os.getCurrentDir()
      os.setCurrentDir(newdir)
      defer: os.setCurrentDir(olddir)
      statements
    
    
    
    import os
    
    proc hi() =
      echo "in:", os.getCurrentDir()
    
    hi()
    
    withcd("bar"):
      echo "It works!"
      hi()
    
    echo "Finish it."
    hi()
    
    
    
    in:/foo
    It works!
    in:/foo/bar
    Finish it.
    in:/foo
    

Reply via email to