-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If ErrorLevel / Is Yori Elevated ? #97
Comments
Nevermind.. I was able to detect elevation with this command:
This seems to work... However, it seems the %IsAdminRun% var can't be used within any IF statement.. !? This is what I ended up with:
I do this with every shell (Cmd, Bash, Pwsh, Git) so I can go back and forth with ease.. |
Firstly, that's a really nice prompt! As you've probably seen, the default includes
Yori also includes a command whose intended purpose is to answer the question of whether the user is elevated:
Note the second case is indicating an admin prompt via the prompt char. |
@malxau yes!.. I noticed I understand the problem with IF.. It is painful to use in CMD, mainly because there are no AND/OR logical operators and code can get quite messy when batch files grow over time. I've also never liked parentheses as separator for code blocks. I actually think the semicolon (;) for single line conditionals is better.. Because IF is not yet fully implemented I also think you'd be in a unique position to do it differently (if desired). I don't think it's on the roadmap, but if there's ever the decision to implement more complex control statements (IF-ELSE-ELSEIF-SWITCH-WHILE) [yeah I know I'm on the wrong lane here], please consider using Curly brackets {} for code blocks, and parentheses () to optionally group conditional blocks (in the likes of C) .. I mean, there's already CMD.exe and Yori runs batch files with it.. I know there are already many scripting languages. But I've always thought a full replacement for CMD could be both backwards compatible (which Yori does by executing batch files with CMD) and implement new features found in other scripting languages. But these are just ideas. The "intcmp" and "grpcmp" solutions worked for me (I just didn't see them documented), BUT.. In the case of "grpcmp" it's language dependent.. So since my default Windows language is spanish, the command:
..Fails even when executed from an elevated prompt, so it would have to be used like this:
But I don't think relaying on locale is a good idea.. One other thing..I also noticed these two issues with Yori: 1. Using the | symbol within a Rem comment breaks the script:
I usually add a separator from Rem and any comment; CMD ignores everything after Rem.. 2. There's a problem with CHDIR/CD and slashes/backslashes in directories.. These commands fail (but they work on CMD.exe): Then these commands work: I think this is unwanted behavior !?.. I do think CHDIR should be more flexible with slashes.. |
So in Yori,
|
2.1. I just noticed that if I keep pressing [TAB] the folder name keeps repeating and the command is invalid (with YORICOMPLETEWITHTRAILINGSLASH enabled and only the folder "DIR TEST" in the current path location):
Based on your example with
I think it would be a great idea to have them documented in the online help. I'm in shock they're not mentioned. Can we get |
|
Hi again!
Have a great week! |
Sorry for the delayed response. I've been working on fixing 2, and although the final change is fairly small, it took a few attempts to get there. This change adds the required escapes before a terminating quote as part of tab completion. The parser has been modified so that when a quote is being swallowed (because it is followed by more text) the escapes are removed. This allows the user to type text after a tab completion, possibly invoking tab completion again, and have the result not contain redundant escapes. For the documentation changes, I understand where you are coming from, but changes require specific text to change to specific values. If there are clear things that would have made things easier for you, please submit a PR that shows the text changes you'd like to see. I'm still unclear on the interactive shell issue. I know other shells make a distinction here, but are you saying the purpose of the distinction is to avoid running expensive init scripts, so a non-interactive instance is the same as an interactive one but with less initialization? Presumably scripts need to be defensive to operate correctly if the extra initialization is performed, so this isn't an environment scripts rely on, it's a performance optimization? Although users can add as much initialization as they'd like, the default configuration is to have tools prefixed with "y" so they can be called from CMD, and aliases to these defined within Yori so the environment functions with familiar commands. Skipping this initialization means scripts would need to add a lot of "y" to be robust to running without aliases. Some aliases are defined explicitly in code, as opposed to initialization scripts. See things like: Lines 196 to 203 in fa655a3
Even aliases like Lines 276 to 283 in fa655a3
Would the intention be to skip this type of initialization too? |
Hi Malcolm..
Having said that, there are probably shells that give some startup options to skip initialization stuff (like running in SAFE MODE), but that's another thing. |
|
I just compiled with VS2019 x64 (Win10 x64) with no errors.. but I can't seem to open a shell..
This works (from an existing Yori prompt over the compiled dir): This (from ConEmu) doesn't; it just just closes down (with exit code x80000003): This throws an error "argument not understood, ignored: /k": Am I missing something? |
My best theory is that this code was compiled, changes were picked up from github, then recompiled - is this correct? 80000003 may be If this doesn't explain it, can you describe more about your build environment? The normal Yori build environment won't create directories like The output of |
The path "D:\Command\Yori" is where I put Yori related stuff.. There's the "Bin/" subfolder (where Yori binaries actually are), a "History/" subfolder, and yesterday I made the "Compiled/" subfolder just to test it. Its content is simply a copy from "yori-ea23dd6242ded3142a4a76f264f5ce55d6a283a2\Bin\amd64". I'm using MSVC 19.27.29112 for x64 on WIndows 10 21H1. I understand what happens with the "/k" switch; I kind of inferred it was the intended behavior. I mentioned it in case it wasn't, because CMD.exe does take the /K switch alone to open the console and keep it open. Yori wouldn't need it because it already does that by default when running yori.exe. But keep in mind some people would expect that to work. |
@malxau I was able to compile Yori and test your changes.. The debugger helped. The %YORIINTERACTIVE% environment var is a nice addition and works perfectly; however, it shows a value (1) only when the shell started in interactive mode, which of course does the job. But perhaps you could consider to add a default value (0) when running in non-interactive mode, to keep consistency (and prevent future type mismatch comparisons). I also tried the %YORIINTERACTIVE% var within a Yori script started from an interactive shell, which (as you've already mentioned) echoed as 1 (INTERACTIVE). My head is spinning a little bit here 😊 ... Because I agree with what you've described it should happen (once interactive, always interactive). But I put it to the test. CMD does it (batch files running from the prompt echo as INTERACTIVE) but Bash doesn't. Bash scripts running from the interactive shell echoed directly as NON-INTERACTIVE, while at the same time environment INIT scripts (profile, .bash_profile, .bashrc) echoed properly as INTERACTIVE for the shell and NON-INTERACTIVE for scripts. Just something I thought was worth mentioning. I noticed YORICOMPLETEWITHTRAILINGSLASH is now disabled; completion no longer uses the trailing backslashes. I tried One other thing if I may ask.. |
Sorry for the delayed response.
For Good point about |
More updates on this... Commit f4ba700 fixes a bug with tab completion and trailing slash Commit 2453bdc allows sdir to sort by directory state Commit 4d686bb defines YORIINTERACTIVE if it's not defined already Commit 7467026, commit 1853054 and commit 9bd74ed allow an easier path to transition to a testing build without compiling it manually. This won't help until there's a new stable build that includes this support, allowing from a transition from that build to a future testing build. I think now this issue should be closed, and if there are further items those can be discussed in their own issues. |
@malxau I tested the changes and everything seems ok. Closing this issue is also on point. Thank you. I do have some comments and/or recommendations, not necessarily issues, but if any of these notes is worth fixing please let me know and I'll open up a different issue:
Then CMD uses the correct name in any case:
I think this qualifies as unintended behavior !?.. It also affects how the prompt shows up.
[Edit 2021-08-24 11:27]
Have a great day! |
For the pandora's box comment, the original Win32 system allowed opens by name, but no way to query names for opened objects. SetCurrentDirectory() follows this model, where a name can be specified and used, but a later call to GetCurrentDirectory() just returns the previously provided name, without adjusting for on-disk case. In NT 3.x, CMD behaves the same way as Yori. NT 4 appears to change this by trying to perform something like GetLongPathName(), which works by querying the filesystem for each component in the path, trying to enumerate the "real" case for the component. This is obviously slow but is also unreliable: there is no guarantee that a user has access to enumerate parent directories. Further, because NTFS allows names differing only by case, performing a case-insensitive enumerate does not guarantee to resolve to the same directory. I believe what NT 4's CMD is doing is going component-by-component, on failure preserving the user specified case, and always using the user specified case in the call to SetCurrentDirectory(). If that works, it displays the case that it found via these component enumerates. This means it needs to keep an internal concept of current directory that differs from the OS concept, as the two have different cases. It's possible for Yori to do the same thing, but it's not trivial and will incur a runtime cost. |
——————————————— 8. Is there a character (or way) to separate multiple commands in aliases?.. Note: I'm no longer given the option to comment and close.. |
Hello @malxau .. I noticed name casing is working now in the latest daily.. 👌😀 A small step for Yori, a great leap for replacing Cmd.. 😎 |
Hello.. I'm new to Yori.. I'm enjoying its simplicity, useful completions, and (thank you for) the aliases.
But I do have some pretty basic issues:
And:
I usually do this in CMD by running any command that requires elevation, which sets the ErrorLevel.. for example:
$ net session>nul 2>&1
$ if ErrorLevel == 0 (Echo We have elevation)
But in a Yori script (Init file) it seems neither if statements, nor the ErrorLevel can be used (conditionally) at all.. Even calling an external script .cmd for this task seems not to work.. Or is there currently a way to do it?
The text was updated successfully, but these errors were encountered: