Feature: Set currently active directory on exit

Something is missing in Far Manager? You have a great idea that should be heard? Write here.
Post Reply
dahaiou
Posts: 5
Joined: Sat 26 Oct, 2019 15:11
Has thanked: 2 times

Feature: Set currently active directory on exit

Post by dahaiou »

Hello,
Repeating this here in its proper place for English questions:
(First posted in the Russian section above by mistake. Sorry about that)

I can't find an option or a way to make FAR manager cd to the currently active directory on exit,
as I am used to on Midnight Commander under Linux.

I use mc in Linux all the time and love it but found Windows mc quite horrible when I tried it.
OTOH FAR manager is just great under Windows, and I am only missing this very useful feature.
Or is there another way to do it maybe?

AFAIU the mc solution is based on a command line option which causes the program to output
the currently active directory to stdout on exit (or to a specific file, can't remember right now),
which can in turn be used by a wrapper script to do a cd to that directory when the program exits.

So, is there another way to do this with the FAR manager, or could I request it to be implemented?
It would seem fairly simple to do, and very useful.

The feature request would be to add a Command line option -d (or any other letter) so that:
-d <filename> = Write currently active directory path to <filename> on exit

Then the corresponding cd on exit functionality could be simply implemented in a bat file.

BR, dahaiou
2useven10
Posts: 5226
Joined: Mon 07 Sep, 2009 10:40
Has thanked: 18 times
Been thanked: 314 times

Feature: Set currently active directory on exit

Post by 2useven10 »

You can create a simple lua script to write active panel directory to anywhere you want.
Example below writes last path to %TMP%\far.lastdir

Code: Select all

Event {
  description = "Save last directory on Exit";
  group = "ExitFAR";
  action = function()
    local f = io.open(win.GetEnv("TMP") .. "\\far.lastdir", "w")
    f:write(APanel.Path0)
    f:close()  
  end
}
Just write code above to file %FARPROFILE%\Macros\scripts\far_exit.lua and restart far.
Then when you close farmanager last active directory should be written to file in UTF-8.
Last edited by 2useven10 on Sat 26 Oct, 2019 19:57, edited 4 times in total.
dahaiou
Posts: 5
Joined: Sat 26 Oct, 2019 15:11
Has thanked: 2 times

Feature: Set currently active directory on exit

Post by dahaiou »

Thanks for the advice!

That solution is _almost_ working for me. On exit the output file is created but apparently
is not written to. It stays as size 0, and far manager exits with the following errors:

Code: Select all

             Exception: 0xC0000005 - EXCEPTION_ACCESS_VIOLATION
Details:   Memory at 0000000000000018 could not be read
errno:
LastError:
NTSTATUS:
Address:   0x7FF6C9A3B2DE - Far.exe!<unknown> (get the pdb)
Source:
Function:  ExitFARW
Module:    C:\Program Files\Far Manager\Plugins\LuaMacro\LuaMacro.dll

0x7FF6C9A3B2DE Far.exe!<unknown> (get the pdb)
0x7FF6C9BD9A67 Far.exe!<unknown> (get the pdb)
0x7FF6C9C376AE Far.exe!<unknown> (get the pdb)
0x7FFB6D981CC7 luafar3.dll!LF_LoadFile
0x000066D82C1E lua51.dll!<unknown> (get the pdb)
0x000066D934D3 lua51.dll!lua_pcall
0x7FFB6D97FAB1 luafar3.dll!LF_SetFindList
0x7FFB6D97C86A luafar3.dll!LF_ExitFAR
0x7FFB7C3391C0 LuaMacro.dll!ExitFARW
0x7FF6C9C2B0B2 Far.exe!<unknown> (get the pdb)
0x7FF6C9C294BA Far.exe!<unknown> (get the pdb)
0x7FF6C9C277D7 Far.exe!<unknown> (get the pdb)
0x7FF6C9C253A2 Far.exe!<unknown> (get the pdb)
0x7FF6C9C51507 Far.exe!<unknown> (get the pdb)
0x7FF6C9AB9E35 Far.exe!<unknown> (get the pdb)
0x7FF6C9BEE861 Far.exe!<unknown> (get the pdb)
0x7FF6C9BEE3C4 Far.exe!<unknown> (get the pdb)
0x7FF6C9BEE67D Far.exe!<unknown> (get the pdb)
0x7FF6C9BEE7A0 Far.exe!<unknown> (get the pdb)
0x7FF6C9BEE7EE Far.exe!<unknown> (get the pdb)
0x7FF6C9BEE756 Far.exe!<unknown> (get the pdb)
0x7FF6C9CCD324 Far.exe!<unknown> (get the pdb)
0x7FFB97FA7BD4 KERNEL32.DLL!BaseThreadInitThunk
0x7FFB9864CED1 ntdll.dll!RtlUserThreadStart


Terminate the process (Y/N)?
Any ideas?
Shmuel
Posts: 6834
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 530 times

Feature: Set currently active directory on exit

Post by Shmuel »

Try to replace f:write(APanel.Path0) with f:write(far.GetCurrentDirectory())
dahaiou
Posts: 5
Joined: Sat 26 Oct, 2019 15:11
Has thanked: 2 times

Feature: Set currently active directory on exit

Post by dahaiou »

BIG Thanks Shmuel and 2useven10. Working perfectly now !!! :)

Here is the final solution, slightly adapted from your suggestions:

The following code in %FARPROFILE%\Macros\scripts\far_exit.lua

Code: Select all

Event {
  description = "Save DOS command to enable doing cd into last directory on Exit";
  group = "ExitFAR";
  action = function()
    local f = io.open(win.GetEnv("TMP") .. "\\far_exit.bat", "w")

    -- Write the complete DOS cd command into a .bat file which can then be called
    -- directly from a wrapper script with no further manipulation
    f:write("cd /D \"" .. far.GetCurrentDirectory() .. "\"")
    f:close()  
  end
}
And the wrapper script in C:\util\far.bat used to start FAR Manager
(Works from anywhere as I have C:\util in the PATH env variable)

Code: Select all

del %tmp%\far_exit.bat
"C:\Program Files\Far Manager\Far.exe" %*
%tmp%\far_exit.bat
2useven10
Posts: 5226
Joined: Mon 07 Sep, 2009 10:40
Has thanked: 18 times
Been thanked: 314 times

Feature: Set currently active directory on exit

Post by 2useven10 »

Shmuel wrote: Sat 26 Oct, 2019 22:03 Try to replace f:write(APanel.Path0) with f:write(far.GetCurrentDirectory())
Oops..
My far version have slightly customized exit procedure.
Lua objects are still alive when ExitFAR event processed so I didn't get any error with initial script.
Shmuel
Posts: 6834
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 530 times

Feature: Set currently active directory on exit

Post by Shmuel »

2useven10 wrote: Sun 27 Oct, 2019 14:15 My far version have slightly customized exit procedure.
Lua objects are still alive when ExitFAR event processed so I didn't get any error with initial script.
As far as I know it is Far objects that are not alive at this moment, not Lua objects.
2useven10
Posts: 5226
Joined: Mon 07 Sep, 2009 10:40
Has thanked: 18 times
Been thanked: 314 times

Feature: Set currently active directory on exit

Post by 2useven10 »

Shmuel wrote: Sun 27 Oct, 2019 14:47 it is Far objects that are not alive at this moment
Ok. It is Far object(s) and it is alive at this moment in my version.
Last edited by 2useven10 on Sun 27 Oct, 2019 19:26, edited 1 time in total.
Post Reply

Return to “Suggestions and Ideas”