AB autocompletion: % shows environment variables
Re: AB autocompletion: % shows environment variables
While I'm sure this "wish" (I guess) makes perfect sense to you, it might help to explain it with a few more words to the rest of us!
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
Re: AB autocompletion: % shows environment variables
of course
typing % in AB would suggest available windows variables
typing % in AB would suggest available windows variables
- Attachments
-
- 2017-04-03_133935.png (10.69 KiB) Viewed 1615 times
-
- 2017-04-03_133725.png (2.08 KiB) Viewed 1615 times
Re: AB autocompletion: % shows environment variables
You could execute !set in the AB.
You could write a script named % that executesand then handle the output as you want, then display it.
To execute: enter %; in AB.
In anther script you can build a list of lines likeand display this. Call the script as shown before.
Advantage of 2nd and 3rd version: you can format the output as you like.
Edit: hope there's no typo in
You could write a script named % that executes
Code: Select all
$vars = runret 'cmd /c set';
To execute: enter %; in AB.
In anther script you can build a list of lines like
Code: Select all
$txt = "ALLUSERSPROFILE = %ALLUSERSPROFILE%"
."<crlf>APPDATA = %APPDATA";
Advantage of 2nd and 3rd version: you can format the output as you like.
Edit: hope there's no typo in
Win11 Pro 223H2 Gerrman
Re: AB autocompletion: % shows environment variables
Realized PeterH's scriptable suggestion.
The solution uses a script and an alias in tandem.
THE SCRIPT
THE ALIAS
Paste this into the addressbar and press ENTER. Adjust the script path if necessary.
Now type @% in the addressbar and you will get a menu of available %variables%. Pick any item from the menu and it's placed in the addressbar.
The script has a setting $showvalue to control whether variable values are displayed in the menu. Personally, I like it better with just the variable names (the menu size is much saner), so this setting is off by default.
Although the menu's supposed to be positioned under the addressbar, it's almost never going to be the case unless you have a large display or a low count of variables.
The solution uses a script and an alias in tandem.
THE SCRIPT
Code: Select all
/*ab-envvars-dropdown.xys
0. configure $showvalue & $menuwidth below, and save script as <xyscripts>\ab-envvars-dropdown.xys
1. set an alias with this (paste this line in the AB):
@%=::load "<xyscripts>\ab-envvars-dropdown.xys";
2. now ENTER @% in the addressbar and you will get a menu of %variables% under the addressbar
3. pick any item from the menu and it will be placed in the addresbar.
*/
/****** CONFIGURATION ******/
$showvalue = 0;
// $showvalue
// 0: show only variable names in the menu
// 1: show value snippets beside variable names
$menuwidth = 50;
// $menuwidth
// max width of menu if $showvalue==1
/** END OF CONFIGURATION **/
$out = runret("%ComSpec% /k set", <xydrive>); // get env.vars from output of SET cmd
$out = gettoken($out, -2, <crlf>,, 1); // remove extra padding lines at end
// construct the popupmenu
$menu = '';
if ($showvalue) { // include values
foreach ($line, $out, <crlf>) { // loop through each %var%=value line
$var = gettoken($line, 1, '='); // get var's name
$val = gettoken($line, 2, '='); // get var's value
$line = '%' . $var . '%' . <tab> . $val; // build menu item as %varname%<tab>value
$line = substr($line,, $menuwidth) . ((strlen($line) > $menuwidth) ? ' ...' : ''); // shorten line to max width and add ellipses
$menu = $menu . <crlf> . $line;
}
}
else { // else skip values
foreach ($line, $out, <crlf>) { // loop through each %var%=value line
$menu = $menu . <crlf> . '%' . gettoken($line, 1, '=') . '%'; // get var name and built menu item as %varname%
}
}
$menu = trim($menu, <crlf>, 'L'); // trim extra delimiter line
$abpos = controlposition('A'); // get addressbar position for popumenu placement
$x = gettoken($abpos, 1, '|'); // AB X
$y = gettoken($abpos, 2, '|') + gettoken($abpos, 4, '|'); // AB Y + AB Height
$pick = popupmenu($menu, $x, $y,,,, <crlf>, ''); // show popupmenu (sep_item='' to show ; in values)
$pick = gettoken(regexmatches($pick, '%[^%]+%'), 1, '|'); // get only the variable name part from picked menu item
if ($pick) {
focus 'A';
sendkeys '^a' . sendkeyesc($pick); // insert in AB (^a select all replaces orig alias str)
}
FUNCTION sendkeyesc($s){return regexreplace($s,'([\{\}\^\~\%\+])','{$1}')}
Paste this into the addressbar and press ENTER. Adjust the script path if necessary.
Code: Select all
@%=::load "<xyscripts>\ab-envvars-dropdown.xys";
The script has a setting $showvalue to control whether variable values are displayed in the menu. Personally, I like it better with just the variable names (the menu size is much saner), so this setting is off by default.
Although the menu's supposed to be positioned under the addressbar, it's almost never going to be the case unless you have a large display or a low count of variables.
Last edited by bdeshi on 10 Oct 2017 16:06, edited 2 times in total.
Reason: The Last Bugfix
Reason: The Last Bugfix
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: AB autocompletion: % shows environment variables
I hope everybody is happy with Sammay's script. (I don't plan to add this kind of autocompletion -- it conflicts with the already existing autocompletion.)
FAQ | XY News RSS | XY Twitter
Re: AB autocompletion: % shows environment variables
[don't mind this post, but for what it's worth, I've updated that script above Don's post. There were some violet-hot glaring mistakes.]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: AB autocompletion: % shows environment variables
Sammy - this is a clean, simple, elegant, useful script - along with the optional alias. Thanks for your work! I was using something similar, but I wasn't getting the values from SET (was from a utility), and I wasn't using such a convenient way to call it, nor using a direct insertion in the address bar. Your level of clear commenting is a good example (especially for some of my large regexes, which look more arcane every time I look back at them.), though most suited for sharing something, of course.
I think it might be useful to add a few xy-specific location variables to it at the bottom, though it would be a little less elegant. I do think it would be convenient. I may do it for my own copy if you're not interested. What do you think?
I'm really not sure what Don meant about conflicting(?) with current autocompletion? There seems to be no downside to me...?
I think it might be useful to add a few xy-specific location variables to it at the bottom, though it would be a little less elegant. I do think it would be convenient. I may do it for my own copy if you're not interested. What do you think?
I'm really not sure what Don meant about conflicting(?) with current autocompletion? There seems to be no downside to me...?
Re: AB autocompletion: % shows environment variables
thanks! and sure, go ahead. (sorry for late reply.)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]