unix path of sftp connection to clipboard

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
AndrasB
Junior Member
Junior Member
Posts: 4
Joined: 2022-10-05, 06:52 UTC

unix path of sftp connection to clipboard

Post by *AndrasB »

Hi,

I have been struggling with this issue for years and I found that Lst2Clip doesn't exactly do what I want (or I couldn't figure out how to do it).
Here's my problem:

I am connecting to Unix servers using the sftp plugin. I'd like to copy paste the source path to the command line without the new line at the end.
The path looks like that:
\\\Secure FTP\name_of_connection\path\to\directory\

For printing a list of files/directories with Lst2Clip works, if I replace the beginning of the path using explicitly the name of the connection like that:

Code: Select all

command: C:\totalcmd\Plugins\Lst2Clip\Lst2Clip.exe /R:"\\\Secure FTP\conn1"="" /R:"\"="/"
parameters: /L:"%L"
My first question: is there a way to make the file listing work regardless of what name_of_connection is (e.g. can I use regex/wildcards)?
My second question: can I copy the source path to the clipboard without the new line and getting rid of the first part of the path like this:
/path/to/directory/
In this case the parameter would be /L:"%P".

Or is there another alternative like a user defined command I could use?

Thanks for your help!
User avatar
Stefan2
Power Member
Power Member
Posts: 4153
Joined: 2007-09-13, 22:20 UTC
Location: Europa

AutoHotkey AHK: unix path of sftp connection to clipboard

Post by *Stefan2 »

Hello 2AndrasB and welcome.

You can do such things with an script, for example here with AutoHotkey:

Code: Select all

; 2022-10-05 Wed 17:00:31 by Stefan2
; unix path of sftp connection to clipboard.ahk
;   https://ghisler.ch/board/viewtopic.php?p=421695#p421695
;   The path looks like that: \\\Secure FTP\name_of_connection\path\to\directory\
;   Wanted path looks like  : /path/to/directory/
;----------------------------------
	;History.txt 9b1 wrote: 
	;08.06.16 Added: Send WM_USER+50 (=1074) with wparam set to 1000..1012 to get index of first file, first item, current item, number of items, active panel
	;08.06.16 Added: Send WM_USER+50 with wparam=1..29 -> returns window handle of control.
	;Get active panel with '1000': Return 1=left TMyListBox2 , Return 2=right  TMyListBox1
;----------------------------------
	SendMessage 1074, 1000, 0, , ahk_class TTOTAL_CMD
	ActivePanel = %ErrorLevel%
	If(ActivePanel=1)
	{
		;ActivePanel=TMyListBox2 
		;LEFT , get 9=leftpath 
		wparam = 9
	}else{
		;ActivePanel=TMyListBox1	
		;RIGHT , get 10=rightpath 
		wparam = 10
	}	
;----------------------------------
	SendMessage 1074, %wparam%, 0, , ahk_class TTOTAL_CMD
	iErrorLevel = %ErrorLevel%	;e.g. currently '68032'
	ControlGetText, strReturnFromTC, , ahk_id %iErrorLevel%
;
	MsgBox DEBUG`n`n%strReturnFromTC% 
		; //---------------------------
		; //unix path of sftp connection to clipboard.ahk
		; //---------------------------
		; //DEBUG
		; //
		; //C:\temp\PurgedFiles\*.*
		; //---------------------------
		; //OK   
		; //---------------------------
;
;----------------------------------
	OldStr := strReturnFromTC
	;just for an test:
	OldStr := "\\\Secure FTP\name_of_connection\path to my\directory\*.*"
;----------------------------------
; or: use an loop here to read TCs' "%L"-list and process that list line-by-line
;----------------------------------
	;                                \\\Secure FTP\name_of_connection\path\to\directory\
	NewStr := RegExReplace(OldStr, "^\\\\\\.+?\\.+?\\(.+)$","$1" )
	StringReplace, NewStr, NewStr, \ , /, all
	StringReplace, NewStr, NewStr, *.* , 
;----------------------------------
	MsgBox DEBUG`n`nOLD:`t %OldStr%`nNEW:`t %NewStr%
			; //---------------------------
			; //unix path of sftp connection to clipboard.ahk
			; //---------------------------
			; //DEBUG
			; //
			; //OLD:	 \\\Secure FTP\name_of_connection\path to my\directory\*.*
			; //NEW:	 path to my/directory/
			; //---------------------------
			; //OK   
			; //---------------------------
;
	strOUT = %strOUT%%NewStr%`r`n
;----------------------------------
	;//OUTPUT:
	;StringTrimRight, strOUT, strOUT, 2
	;Clipboard := strOUT
;----------------------------------




automate/script TC with AutoHotkey AHK
viewtopic.php?p=350976#p350976

TC9: "Send WM_USER+50 with wparam" - how-to? (Just some basic examples with AutoHotkey AHK)
viewtopic.php?t=44451



I don't know what you know about AHK and scripting, so just ask here for further advice....
But I think I had not understood your wish correctly?





 
AndrasB
Junior Member
Junior Member
Posts: 4
Joined: 2022-10-05, 06:52 UTC

Re: unix path of sftp connection to clipboard

Post by *AndrasB »

Hi 2Stefan2 (or is the first 2 superfluous?)!

Thank you for taking the time to respond. I have been doing quite a bit of scripting but I don't have the time to dig into AHK.
I presume the part of my issue that involves regex makes it necessary to use AHK. If it is so would it be possible to tackle the problem (with explicit connection name, hence no need for regex) with a combo of inbuilt commands and lets say cygwin/sed or maybe powershell if it's possible to just replace "\" with "/".
Basically cm_CopySrcPathToClip does the part where I get the path of the source directory I'd like to paste into my Unix terminal. All I need is replacing the backslashes and get rid of part \\\Secure FTP\conn1.
Can I pipe the output of cm_CopySrcPathToClip into an external command (e.g. sed) and do the job? Lst2Clip does the replacements, however it is useless with the new line at the end coz I'm using the path in terminal commands.
User avatar
Stefan2
Power Member
Power Member
Posts: 4153
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: unix path of sftp connection to clipboard

Post by *Stefan2 »

Hi 2AndrasB

Many thinks are possible.
TC provide you parameters to access properties, and you can use the scripting tool of your choice to process the info.
AHK works best for that, as it is a small standalone exe (best in TC folder) and has all need commands. But you can use DOS, PoSh, JS, VBS, ...
Just tell us what you want.

- - -


"""Can I pipe the output of cm_CopySrcPathToClip """

With AHK you can:
Dummy code: sendmessage 1704 , 0 , 2029 , %myTCid%
2029 => Number for cm_CopySrcPathToClip-command (see TOTALCMD.INC text file)

Or with any other tool supporting sendmessage/postmessage.



Without AHK try an button with this simple DOS command:

Commando: cmd /c
Parameters: echo "%P" |clip
or
Commando: cmd /c
Parameters:echo "%P" >"C:\Temp\TcTempFile.txt"

Now use SED to process the temp file content ...

- - -

Or use a batch for all need commands:
test.cmd
@ECHO OFF
SET myPath=%1
ECHO %myPath%
path\to\SED 's_\_/_g' %myPath% (don't know if that works that way)
ECHO %myPath% | clip
PAUSE

Commando: C:\temp\test.cmd
Parameters: "%P"

- - -


All depends.
And see my sig for more collected info
Fla$her
Power Member
Power Member
Posts: 2295
Joined: 2020-01-18, 04:03 UTC

Re: unix path of sftp connection to clipboard

Post by *Fla$her »

2AndrasB
lst2clip-u:
Command: %COMMANDER_PATH%\Utils\lst2clip-u\lst2clip-u.exe
Parameters: /R:"\\\%B+\%B+1"="" /R:"\"="/" /L:"%WL"
Overquoting is evil! 👎
AndrasB
Junior Member
Junior Member
Posts: 4
Joined: 2022-10-05, 06:52 UTC

Re: unix path of sftp connection to clipboard

Post by *AndrasB »

Hi 2Stefan2,

Thanks for listing these options, they got me started and I have ended up using the following solution for copying the source path to the clipboard without the sftp prefix and replacing backslashes with forward slashes:

Command=cmd /c
Parameters=echo | set /p dummy="%P" | sed.exe 's/.*Secure FTP\\\[a-zA-Z_]*\\\/\//g; s/\\\/\//g' | clip

I have added C:\Cygwin64\bin\ to PATH.

Hi 2Fla$her,

Thanks for your contribution as well. Could you please elaborate on how lst2clip-u works (what does %B mean)?
Can you confirm the origin of that plugin?
User avatar
AntonyD
Power Member
Power Member
Posts: 1246
Joined: 2006-11-04, 15:30 UTC
Location: Russian Federation

Re: unix path of sftp connection to clipboard

Post by *AntonyD »

lst2clip-u
Are somewhere the manuals for this util? With explanations - what I should pass to the input and how it supposed to be working?
Last edited by AntonyD on 2022-10-07, 10:10 UTC, edited 2 times in total.
#146217 personal license
Fla$her
Power Member
Power Member
Posts: 2295
Joined: 2020-01-18, 04:03 UTC

Re: unix path of sftp connection to clipboard

Post by *Fla$her »

AndrasB wrote: 2022-10-07, 09:40 UTCCould you please elaborate on how lst2clip-u works?
About the same as Lst2Clip, only with unicode support, long paths and with some inconsequential little things, including the absence of a line break from the bottom, as you requested. There is no English readme, so I did not attach it. Maybe afterwards I will translate it with bringing it into proper shape.
AndrasB wrote: 2022-10-07, 09:40 UTCwhat does %B mean
This parameter was added at my request in the previous TC version. See the English help on the options for the button bar.
AndrasB wrote: 2022-10-07, 09:40 UTCCan you confirm the origin of that plugin?
Which plugin are we talking about? This is a utility posted on another forum by one of the members of the TC community.
Last edited by Fla$her on 2022-10-07, 10:15 UTC, edited 1 time in total.
Overquoting is evil! 👎
User avatar
AntonyD
Power Member
Power Member
Posts: 1246
Joined: 2006-11-04, 15:30 UTC
Location: Russian Federation

Re: unix path of sftp connection to clipboard

Post by *AntonyD »

This is a utility posted on another forum by one of the members of the TC community.
And how is the functionality of this program better than the built-in command "Copy selected names to Clipboard"?
For example, can this utility create a list of files in one line? And not as it is now - in the form of a multi-line list.
Can the utility limit the created list to some number of entries?
For example, I want to select the first 10 of the highlighted ones and get a single-lined list of them?
Last edited by AntonyD on 2022-10-07, 10:31 UTC, edited 1 time in total.
#146217 personal license
Fla$her
Power Member
Power Member
Posts: 2295
Joined: 2020-01-18, 04:03 UTC

Re: unix path of sftp connection to clipboard

Post by *Fla$her »

2AntonDudarenko
You'd read the topic first.
AntonDudarenko wrote: 2022-10-07, 10:10 UTCFor example, can this utility create a list of files in one line? And not as it is now - in the form of a multi-line list.
Can. Online translation:
Sinclair83 wrote:Keys:
/P:"prefix"
/S:"suffix"
No comments. Everything is the same here as before. The only difference is the ability to add a double quote. To do this, write two single (apostrophe) in a row anywhere in the prefix and/or suffix.

/R:"a"="b"
Replacing substring a with b (a is old; b is new).
Important! The a value is case-sensitive.
b can be empty (a is not). When b="", substring a will be removed from the result.
It is acceptable to use the /R key more than once. The replacements will be made in the same sequence in which the /R keys follow each other.

/L:"x" (x - see TC help)

/UC
The resulting text = uppercase letters.

/LC
The resulting text = lowercase letters.

/TR
Transliteration according to GOST 16876-71. Watch here

/OS-z
The result is in one line (z is the number of characters on the right that need to be cut off from the resulting text). /OS is identical to /OS-0, but the first is preferable (bypassing the z check for a number).

Following keys that differ from each other is not essential, it can be arbitrary.
If someone is not satisfied with GOST, then you can make your own amendments by using the /R key.

The algorithm of operation is as follows:
1. Reading the list file + passing the prefix, suffix and line feed
2. Cutting off excess
3. Transliteration
4. Replacement
5. Changing the case of the text

Yes. Also added removal of all previously allocated (cm_ClearAll) at the end of the work.
It's difficult to call it a reference material, but what is, that is.
Overquoting is evil! 👎
AndrasB
Junior Member
Junior Member
Posts: 4
Joined: 2022-10-05, 06:52 UTC

Re: unix path of sftp connection to clipboard

Post by *AndrasB »

2Fla$her

Thanks for the clarifications, I will give las2clip-u a go.
I can see that you're very specific about plugin vs utility (saw your reply in another topic as well).
Can you tell me what is the difference? Is there an official page for TC utilities like the one for plugins?
Fla$her
Power Member
Power Member
Posts: 2295
Joined: 2020-01-18, 04:03 UTC

Re: unix path of sftp connection to clipboard

Post by *Fla$her »

AndrasB wrote: 2022-10-07, 10:52 UTCCan you tell me what is the difference?
Plugins are modules that are directly embedded into the program interface within the framework of the functionality specified by this interface, in this case consisting of 4 types (wlx, wfx, wdx, wcx). And utilities are independent tools that can complement the functionality of the main program tied to its handle (they are more usually called addons) or not, depending on the preferences of the authors.
AndrasB wrote: 2022-10-07, 10:52 UTCIs there an official page for TC utilities like the one for plugins?
There is.

AntonDudarenko wrote: 2022-10-07, 10:10 UTCFor example, I want to select the first 10 of the highlighted ones and get a single-lined list of them?
No, it's pretty specific. You can use a chain of commands to do this: 2049,2053,2054,524,cm_Select 10,2021
Instead of 2021, you can specify em_ command with the execution of the specified utility.
Overquoting is evil! 👎
Post Reply