cm_Set and cm_SetIfEmpty

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

cm_Set and cm_SetIfEmpty

Post by *white »

I suggest to implement a new internal command cm_Set which works similar to the set command in cmd.exe.
I also suggest to implement a new internal command cm_SetIfEmpty which only sets a variable if it doesn't exist yet.

Syntax:

Code: Select all

cm_Set var=value         ; set environment variable
cm_Set [var_part]        ; show list of environment variables, all vars (no parameter) or all vars starting with var_part
cm_SetIfEmpty var=value  ; set environment variable only if it doesn't exist yet
Fla$her
Power Member
Power Member
Posts: 2309
Joined: 2020-01-18, 04:03 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *Fla$her »

What's the point? Give an example of using variables that you create within the current session (not at the start with autorun).
Overquoting is evil! πŸ‘Ž
User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: cm_Set and cm_SetIfEmpty

Post by *white »

The point, of course, is to give control over TC's environment space.

Use cases can be many things, it's primarily limited by one's lack of imagination. Some examples:

Set options for a program that uses a environment variable and then run that program
Command: cm_Set myprogram_options=-r -o 64,c:\myprogram\myprogram.exe

Make sure a used environment variable exists, otherwise the variable name and percent signs will be used unchanged
Command: cm_SetIfEmpty my_var=empty,c:\myprogram\myprogram.exe %my_var%

Store a file name to be used later (in this TC session) by several programs of your choice
Command: cm_Set myvar=
Parameter: %P%N

Set the path for a certain program
Command: cm_SetIfEmpty path_start=%path%,cm_Set path=%path_start%;c:\myprogram\bin,c:\myprogram\myprogram.exe
User avatar
funkymonk
Senior Member
Senior Member
Posts: 416
Joined: 2013-12-04, 09:56 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *funkymonk »

Following the many threads and discussions in the forum, there seems to be an increasing demand for scripting or scripting-like functionality in TC:

* commands with (more) parameters
* command lists (also with commands that support parameters, e.g., for defining shortcuts)
* conditional creation of env variables (as in this thread)
* ...

It is great to see that many requests are considered in new TC versions. Thank you indeed, Mr. Ghisler. This is awesome.

But: I increasingly get the feeling that many improvements related to the items above often just "retrofit" features in very specific places in TC (which do not work everywhere in TC, or only with additional effort).

Examples:
* Some commands support parameters, but not when defining shortcuts. --> detour via user commands
* Conditional definition of env variables --> since if-then-else is not supported, cm_Set and cm_SetIfEmpty would be required
* Comma-separated command lists are supported in many places, but sometimes there can be spaces (em_commands) or must not be spaces (autostart commands in view mode definitions) around the commas --> inconsistency
* ...

Wouldn't it be better to think about a real scripting functionality in TC (with a consistent syntax)?
Of course the effort would be quite big, but probably this would provide more consistency and simplify many tasks...

I really fear, that too many situation-specific or context-specific improvements will clutter TC in the long run.


(Maybe this discussion deserves a separate thread -- or should not be raised at all. I will let the forum admins decide.)
Fla$her
Power Member
Power Member
Posts: 2309
Joined: 2020-01-18, 04:03 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *Fla$her »

2white
In the first and third examples, you will create only a variable, and I asked to give examples of their use.
white wrote: ↑2022-10-13, 10:55 UTC Make sure a used environment variable exists, otherwise the variable name and percent signs will be used unchanged
Command: cm_SetIfEmpty my_var=empty,c:\myprogram\myprogram.exe %my_var%
Why is 'empty' here? There should be nothing at all logically.
And why do you need something with percentages as a parameter to the program? Didn't you know that in Command field, an empty environment variable is expanded to an empty value? There won't be an entry like %my_var%.
I'm asking you to give a real example from practice, not something elusive.
white wrote: ↑2022-10-13, 10:55 UTC Set the path for a certain program
Command: cm_SetIfEmpty path_start=%path%,cm_Set path=%path_start%;c:\myprogram\bin,c:\myprogram\myprogram.exe
And why do you want to do this during the session, and not at the time of TC launch?

funkymonk wrote: ↑2022-10-13, 11:15 UTC Maybe this discussion deserves a separate thread
There are such topics. You can search.
Overquoting is evil! πŸ‘Ž
mmm
Member
Member
Posts: 120
Joined: 2020-08-10, 12:32 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *mmm »

funkymonk,
I find your concern totally legitimate.
Glad you decided to be vocal about it.

mmm
User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: cm_Set and cm_SetIfEmpty

Post by *white »

Fla$her wrote: ↑2022-10-13, 12:13 UTC In the first and third examples, you will create only a variable, and I asked to give examples of their use.
Their use is explained in the title above it.
Fla$her wrote: ↑2022-10-13, 12:13 UTC Didn't you know that in Command field, an empty environment variable is expanded to an empty value? There won't be an entry like %my_var%.
Are you sure? Try this button and see what ini name is used:

Code: Select all

TOTALCMD#BAR#DATA
"%commander_exe%" /i="%temp%\tc_%myini%.ini"

%commander_exe%
Test non-existing environment vrariable


-1
Fla$her wrote: ↑2022-10-13, 12:13 UTC
white wrote: ↑2022-10-13, 10:55 UTC Set the path for a certain program
Command: cm_SetIfEmpty path_start=%path%,cm_Set path=%path_start%;c:\myprogram\bin,c:\myprogram\myprogram.exe
And why do you want to do this during the session, and not at the time of TC launch?
Why should I want to change the path at the time of TC launch for a program I might not use?
Fla$her
Power Member
Power Member
Posts: 2309
Joined: 2020-01-18, 04:03 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *Fla$her »

white wrote: ↑2022-10-13, 13:33 UTCTheir use is explained in the title above it.
There are no specific live examples that would be useful outside of scripts.
white wrote: ↑2022-10-13, 13:33 UTCAre you sure? Try this button and see what ini name is used:
Yes, I'm sure, because I actively use it. Topics: 1, 2.
History.txt wrote:29.07.18 Fixed: Distinguish between empty environment variables and non-existing environment variables. Replace %variable% with empty string in the first case (32/64)

white wrote: ↑2022-10-13, 10:55 UTCWhy should I want to change the path at the time of TC launch for a program I might not use?
In PATH are written paths to directories with programs, not the full names of programs. Does it make sense to add a directory there just to run the program only within one session? To me, such use seems unproductive. I don't remember any situations when I needed something like that.

mmm wrote: ↑2022-10-13, 12:50 UTCGlad you decided to be vocal about it.
See one of the author's answers.
Last edited by Fla$her on 2022-10-13, 16:43 UTC, edited 1 time in total.
Overquoting is evil! πŸ‘Ž
User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: cm_Set and cm_SetIfEmpty

Post by *white »

Fla$her wrote: ↑2022-10-13, 14:35 UTC
white wrote: ↑2022-10-13, 13:33 UTCTheir use is explained in the title above it.
There are no specific live examples that would be useful outside of scripts.
Scripts, other TC buttons, programs that use certain environment variables, program that support environment variables in their configuration.
Fla$her wrote: ↑2022-10-13, 14:35 UTC
white wrote: ↑2022-10-13, 13:33 UTCAre you sure? Try this button and see what ini name is used:
Yes, I'm sure, because I actively use it. Topics: 1, 2.
History.txt wrote:29.07.18 Fixed: Distinguish between empty environment variables and non-existing environment variables. Replace %variable% with empty string in the first case (32/64)
I see what you mean. With "empty" I meant a non-existing environment variable, not a variable that holds an empty string.
Fla$her wrote: ↑2022-10-13, 14:35 UTC
white wrote: ↑2022-10-13, 10:55 UTCWhy should I want to change the path at the time of TC launch for a program I might not use?
In PATH are written paths to directories with programs, not the full names of programs. Does it make sense to add a directory there just to run the program only within one session? To me, such use seems unproductive. I don't remember any situations when I needed something like that.
Some programs are weird and require their bin folder to be in the path or they can't find their libraries.
Fla$her
Power Member
Power Member
Posts: 2309
Joined: 2020-01-18, 04:03 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *Fla$her »

white wrote: ↑2022-10-13, 15:19 UTCScripts, other TC buttons, programs that use certain environment variables, program that support environment variables in their configuration.
In my memory, there were a couple of requests that concerned remembering the full file name. This is copying it to the folder of the active panel or returning to it by cd. I don't remember anything else useful. So I'm asking you to give live examples, not abstract ones.

In any case, you can make hotkeys (autorun: SetHotkeyAction + SetEnv + GetCurrentItem) to create environment variables during the session without TC commands.
white wrote: ↑2022-10-13, 15:19 UTCI see what you mean. With "empty" I meant a non-existing environment variable, not a variable that holds an empty string.
Anyway I don't understand the logic of cm_SetIfEmpty my_var=empty,. If there is no variable, then must be done so that it does not exist? Meaninglessness.
And in this case, the name should be changed from cm_SetIfEmpty to cm_SetIfNotExist, cm_SetIfAbsent or cm_SetIfMissing.
white wrote: ↑2022-10-13, 15:19 UTCSome programs are weird and require their bin folder to be in the path or they can't find their libraries.
To run, you always need the folder where the program is located. It doesn't matter if it's bin or something else.
But I'm beginning to understand what you need. You often conduct tests with some program and want to run it regardless of the change of the working directory (tree navigating, tab switching, etc.). Am I thinking in the right direction?
Overquoting is evil! πŸ‘Ž
User avatar
jinsight
Senior Member
Senior Member
Posts: 299
Joined: 2003-02-25, 19:47 UTC
Location: Wooster, Ohio, USA

Re: cm_Set and cm_SetIfEmpty

Post by *jinsight »

2funkymonk,

I, too, find your concern totally legitimate and am glad you decided to be vocal about it.

I, too, would prefer a scripting or scripting-like functionality in TC rather than a shoe-horned "retrofit"
response that creates many situation-specific or context-specific improvements that will clutter TC in the long run.
License #1945
Windows 10 Pro x64
Version 22H2 (OS Build 19045.3930)
TC 11.00 x64 and x86, Everything 1.5.0.1366a x64, QAP 11.6.3.1 x64
Fla$her
Power Member
Power Member
Posts: 2309
Joined: 2020-01-18, 04:03 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *Fla$her »

2jinsight
I suggest you also follow my link from the bottom of the post.
Overquoting is evil! πŸ‘Ž
User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: cm_Set and cm_SetIfEmpty

Post by *white »

Fla$her wrote: ↑2022-10-13, 16:08 UTC
white wrote: ↑2022-10-13, 15:19 UTCI see what you mean. With "empty" I meant a non-existing environment variable, not a variable that holds an empty string.
Anyway I don't understand the logic of cm_SetIfEmpty my_var=empty,. If there is no variable, then must be done so that it does not exist? Meaninglessness.
That example would assign the string "empty" to the variable my_var. It could be any value the user wants. Sorry for the confusion by using this example.
Fla$her wrote: ↑2022-10-13, 16:08 UTC And in this case, the name should be changed from cm_SetIfEmpty to cm_SetIfNotExist, cm_SetIfAbsent or cm_SetIfMissing.
Or cm_SetIfUndefined, or whatever Ghisler would prefer.
Fla$her wrote: ↑2022-10-13, 16:08 UTC
white wrote: ↑2022-10-13, 15:19 UTCSome programs are weird and require their bin folder to be in the path or they can't find their libraries.
To run, you always need the folder where the program is located. It doesn't matter if it's bin or something else.
It isn't about the folder where the program is located in order to run the program. In that case you would simply enter full path of the program. It's about programs that use the path variable to locate their library files.
Fla$her wrote: ↑2022-10-13, 16:08 UTC But I'm beginning to understand what you need. You often conduct tests with some program and want to run it regardless of the change of the working directory (tree navigating, tab switching, etc.). Am I thinking in the right direction?
No.
Fla$her
Power Member
Power Member
Posts: 2309
Joined: 2020-01-18, 04:03 UTC

Re: cm_Set and cm_SetIfEmpty

Post by *Fla$her »

2white
I haven't seen any live examples from you.
white wrote: ↑2022-10-13, 17:47 UTCSorry for the confusion by using this example.
Thanks at least for clarifying.
white wrote: ↑2022-10-13, 17:47 UTCIn that case you would simply enter full path of the program.
Won't you get tired of repeatedly writing the full path in each session?
white wrote: ↑2022-10-13, 17:47 UTC It's about programs that use the path variable to locate their library files.
Well, these are interrelated things.
Overquoting is evil! πŸ‘Ž
User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: cm_Set and cm_SetIfEmpty

Post by *white »

Fla$her wrote: ↑2022-10-13, 18:12 UTC I haven't seen any live examples from you.
I'm not sure what you mean by "live examples".
Fla$her wrote: ↑2022-10-13, 18:12 UTC Won't you get tired of repeatedly writing the full path in each session?
The commands I gave were meant to be used for example in a button. Not to be typed each session.
Post Reply