AB autocompletion: % shows environment variables
Posted: 03 Apr 2017 00:03
thanks
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
Code: Select all
$vars = runret 'cmd /c set';Code: Select all
$txt = "ALLUSERSPROFILE = %ALLUSERSPROFILE%"
."<crlf>APPDATA = %APPDATA";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}')}
Code: Select all
@%=::load "<xyscripts>\ab-envvars-dropdown.xys";