"Copy Path" regexp transformation?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
ryanagler
Posts: 36
Joined: 01 May 2007 16:36

"Copy Path" regexp transformation?

Post by ryanagler »

So I have been using XY and Directory Opus for over a year now, and I find myself switching back and forth because each one has its specialty. I find XY to be orders of magnitude faster browsing linux network shares, which is what I spend mot of my time working with, so Id prefer using XY for as much as I can.

There is one thing Opus has that I just cant do without, and that is being to copy a file or folder name to the clipboard and have a regexp transform it to a unix-style path for pasting. For example, say i copy a folder that normally would put the text string "S:\usr\local\apache2\conf" into the clipboard. I am looking for something in XY that would automatically apply a regexp to that string to make it "/usr/local/apache2/conf" Does such a feature exist in XY?

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: "Copy Path" regexp transformation?

Post by admin »

ryanagler wrote:For example, say i copy a folder that normally would put the text string "S:\usr\local\apache2\conf" into the clipboard. I am looking for something in XY that would automatically apply a regexp to that string to make it "/usr/local/apache2/conf" Does such a feature exist in XY?
Currently not, but it's very easy to add, of course. There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!

PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...

Code: Select all

S:\usr\local\apache2\conf
/usr/local/apache2/conf

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: "Copy Path" regexp transformation?

Post by jacky »

admin wrote:There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
/me gets all excited, takes note : v7.2 :D
Proud XYplorer Fanatic

ryanagler
Posts: 36
Joined: 01 May 2007 16:36

Re: "Copy Path" regexp transformation?

Post by ryanagler »

admin wrote:Currently not, but it's very easy to add, of course. There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
awesome!
admin wrote:PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...
There are some exceptions, but 90% of the time, yes! If you could add it that would be great!

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: "Copy Path" regexp transformation?

Post by admin »

ryanagler wrote:
admin wrote:Currently not, but it's very easy to add, of course. There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
awesome!
admin wrote:PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...
There are some exceptions, but 90% of the time, yes! If you could add it that would be great!
90% is not enough. So, what RegExp do you use for this job?

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: "Copy Path" regexp transformation?

Post by admin »

jacky wrote:
admin wrote:There is only one puzzle stone missing here, and that's a scripting command for string manipulation using regexp. This is actually planned for scripting 2.0 (which will happen in v7.2 or so)!
/me gets all excited, takes note : v7.2 :D
Okay, I added it right now. :)

Not sure about the name of the function.
regexpreplace is a bit long... what about regrep??

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: "Copy Path" regexp transformation?

Post by j_c_hallgren »

admin wrote:Not sure about the name of the function.
regexpreplace is a bit long... what about regrep??
I'd suggest: regexrpl ...or... regexrep as I think regex needs to be there.

As I initially read regrep as re-grep...
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: "Copy Path" regexp transformation?

Post by admin »

j_c_hallgren wrote:
admin wrote:Not sure about the name of the function.
regexpreplace is a bit long... what about regrep??
I'd suggest: regexrpl ...or... regexrep as I think regex needs to be there.

As I initially read regrep as re-grep...
Yep. I made a little research and found that "RegExReplace" is a quite common name for it, so I take it.

It will look like this:

Code: Select all

RegExReplace OutputVar, InputString, RegExPattern, Replacement, MatchCase

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: "Copy Path" regexp transformation?

Post by admin »

admin wrote:PS: Is this always like your example? I mean: cut the drive letter and change the slashes? In that case I could add it immediately...

Code: Select all

S:\usr\local\apache2\conf
/usr/local/apache2/conf
v6.80.0112 can do this now. Create a UDC "Run Script" and use the following multiline script (use Edit... button to enter it):

Code: Select all

// copy current item as unix path
  mid $p, <curitem>, 3;
  replace $p, $p, "", "/";
  copytext $p;
Assign a KS, e.g. Ctrl+U, and it will copy the currently selected item as unix path to the clipboard. :)


PS: why was I so keen to add it already now? Because now I can do this:

Code: Select all

// copy current item as xyplorer.com URL
  replace $p, <curitem>, "", "/";
  replace $p, $p, "D:/www/xyplorer.com/code", "http://www.xyplorer.com";
  copytext $p;
Very nice! :D

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: "Copy Path" regexp transformation?

Post by jacky »

admin wrote:
jacky wrote:/me gets all excited, takes note : v7.2 :D
Okay, I added it right now. :)
Awesome!! :D

Haven't played with it much, but I couldn' resist a few tries... I have a question though : it seems that caret (^) & dollar ($) only match the very start and very end of the entire string, I think it'd be better if it could match the beginning & end of every line instead (or at least add an option to switch to this mode).
(On your end, I beleive all it takes is to put Multiline to True.)

PS: this is pretty cool stuff!! :D
Proud XYplorer Fanatic

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: "Copy Path" regexp transformation?

Post by admin »

jacky wrote:(On your end, I beleive all it takes is to put Multiline to True.)
Okay, done. All wishes should be that easy! :wink:

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: "Copy Path" regexp transformation?

Post by jacky »

admin wrote:
jacky wrote:(On your end, I beleive all it takes is to put Multiline to True.)
Okay, done. All wishes should be that easy! :wink:
Cool, thanks :)

So, couple of (quick) suggestions that seems to come naturally...

- mid : might be nice to have <start> to support negative values, to start from the end, so mid $a, "Maxi", -2 would return "xi"

- locate : returns the position on a string. locate $i, "Maxi", "a" would return 2

- inc : to increment an integer value. set $a, 2; inc $a, 3; msg $a; inc $a, -7; msg $a; would say "5" the first time, and "-2" the second time

- regexp : to use a regexp to search/extract a string, so regexp $a, "C:\Folder\Sub\Here", ":\\(.+?)\", "Main folder is $1" would return "Main folder is Folder"
Proud XYplorer Fanatic

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Post by PeterH »

Some notes from me, too...

On "SubStr", the very last character is addressed by Start = -1, while the very first is Start = 0. I wouldn't really expect this.
(And on a string-instruction in a script I would prefer to count the first char as 1 - I don't think of an offset here, but of a position in the string?)

Isn't the "Incr"-instruction "Add"? It adds second and third operand, and returns result as the first?
(Only, if you don't plan to define "Set result, var1+var2+var3" or so. But I don't expect that...)

Is there a reason to limit "AddStr" to 3 variables? Some more could be quite handy. (While 3 will do in most cases...)

For "functions" requiring a number (like a pos, length, ...): what happens, if it is alfa or so?

But one thing must be said: the abilities of scripting are enhanced by these few variable-manipulating instructions by a whole world!

Enjoy your bootcamp, or how did you call it :D

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Post by jacky »

PeterH wrote:On "SubStr", the very last character is addressed by Start = -1, while the very first is Start = 0. I wouldn't really expect this.
(And on a string-instruction in a script I would prefer to count the first char as 1 - I don't think of an offset here, but of a position in the string?)
As Don said, it goes along with the substr function of PHP. It is common usage, so it makes sense to find it here in XY as well.
PeterH wrote:For "functions" requiring a number (like a pos, length, ...): what happens, if it is alfa or so?
As hinted in a few examples, if the first characters of the string are numbers, their value will be used, otherwise zero.
"foo" => 0
"foo2" => 0
"2foo3" => 2
PeterH wrote:But one thing must be said: the abilities of scripting are enhanced by these few variable-manipulating instructions by a whole world!
Agreed!

BTW, the next logical step here now (but for after v7.0 of course) has to be condition (IF..THEN..ELSE..) and loops (WHILE), right? 8)
Proud XYplorer Fanatic

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Post by PeterH »

jacky wrote:As Don said, it goes along with the substr function of PHP. It is common usage, so it makes sense to find it here in XY as well.
I'm afraid there are a lot of systems, some count strings from position 0, some from pos 1. Wouldn't it be best to take the better version - whatever? And I wouldn't have posted my question, if there wouldn't be the discrepancy of 1 = 2nd character, but -1 = 1st character from the end. So if 0 is the first char, I would ask for -0 to be the last char... :oops:

Thanks for the info about mis-formatted numbers, very usefull to know what to expect.

And yes: If...Then...Else... and some kind of loop (like I said above: different systems have different commands, like While, For, Do, ...). But what I also would like to see are Do...End groups. (Some use Begin...End instead, don't know what PHP does...)

Post Reply