You are not logged in.
READ THE EDIT ON POST #7 FOR A BETTER SOLUTION
I have a very short Lua script that makes a backup copy of files on save for SciTE:
function OnBeforeSave(filename)
os.remove (filename.."~")
os.rename (filename, filename.."~")
return false
end
The problem with this code is that the newly saved file doesn't keep the file permissions of the previous version. My first thought was to do something like this:
os.execute ("chmod $(stat --format=%a filename~) filename")
This doesn't work because the value of 'filename' isn't passed to the execute command no matter how I reference it (the Bash way). I noticed that all of the necessary commands are in the Lua file system package, but I can't figure out how to make it work, nor can I find any modern examples. So, I need to know either how to pass variables from Lua to Bash, or how to use the Lua file system class.
Last edited by skottish (2008-09-19 21:18:12)
Offline
What about this?
os.execute ("chmod $(stat --format=%a " .. filename .. "~) ".. filename)
Last edited by kett (2008-09-12 21:41:28)
Offline
What about this?
os.execute ("chmod $(stat --format=%a " .. filename .. "~) ".. filename)
Thanks kett,
That was one of the variations that I tried. I know for a fact that Bash never sees any values for filename. I tested with plain echo and nothing works.
Offline
So, that doesn't work? From, what I'm reading, you tried
os.execute("echo "..filename)
And it didn't work? Cause I just tried that myself and it works for me.
Offline
You know what? I'm wrong. Yes, echo will print to to a launching terminal. You're giving me hope that the problem is in the way I'm looking at it.
With the code you have above, Lua isn't seeing the ~ at the end. This is the error. 'a' is my test file:
chmod: cannot access `/home/skottish/downloads/a': No such file or directory
--EDIT--
Oh crap. I'm a moron. The file isn't created yet, is it?
--EDIT 2--
Yes, I am a moron. This is the functioning Lua startup script for SciTE:
function OnBeforeSave(filename)
os.remove (filename.."~")
os.rename (filename, filename.."~")
return filename
end
function OnSave(filename)
os.execute ("chmod $(stat --format=%a " .. filename .. "~) ".. filename)
return false
end
Thanks a million. You're help was perfect kett.
Last edited by skottish (2008-09-13 00:57:44)
Offline
Yea, the one thing I've always found with programming is that it is way too easy to be a 'moron'. The first language I find that prevents that, I'm there.
Offline
I'm just glad that you led me to a solution. I'm finding more and more that SciTE is simply the best text editor for me. And, slowly but surely I'm (we're) working out the last few quirks.
Thanks again kett. I appreciate your patience.
--EDIT--
There is a far more simple way to go about this. The following will do exactly what the last code does:
function OnBeforeSave(filename)
os.execute("cp " .. filename .. " " .. filename .. "~")
return false
end
To have backups of everything saved into the /tmp directory geany style:
function OnBeforeSave(filename)
os.execute("cp " .. filename .. " /tmp/$(basename " .. filename .. ")" .. "_" .. os.time())
return false
end
Last edited by skottish (2008-09-19 21:28:50)
Offline