AB autocompletion: % shows environment variables

Features wanted...
Post Reply
yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

AB autocompletion: % shows environment variables

Post by yusef88 »

thanks

RalphM
Posts: 1935
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: AB autocompletion: % shows environment variables

Post by RalphM »

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%)

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: AB autocompletion: % shows environment variables

Post by yusef88 »

of course :lol:
typing % in AB would suggest available windows variables
Attachments
2017-04-03_133935.png
2017-04-03_133935.png (10.69 KiB) Viewed 1615 times
2017-04-03_133725.png
2017-04-03_133725.png (2.08 KiB) Viewed 1615 times

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: AB autocompletion: % shows environment variables

Post by Filehero »

Good idea!

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

Re: AB autocompletion: % shows environment variables

Post by PeterH »

You could execute !set in the AB.

You could write a script named % that executes

Code: Select all

  $vars = runret 'cmd /c set';
and 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 like

Code: Select all

   $txt = "ALLUSERSPROFILE = %ALLUSERSPROFILE%"
   ."<crlf>APPDATA         = %APPDATA";
and 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 :ninja:
Win11 Pro 223H2 Gerrman

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: AB autocompletion: % shows environment variables

Post by bdeshi »

Realized PeterH's scriptable suggestion.
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}')}

ab-envvars-dropdown.xys
(3.1 KiB) Downloaded 82 times
THE ALIAS
Paste this into the addressbar and press ENTER. Adjust the script path if necessary.

Code: Select all

@%=::load "<xyscripts>\ab-envvars-dropdown.xys";
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.
Last edited by bdeshi on 10 Oct 2017 16:06, edited 2 times in total.
Reason: The Last Bugfix
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: AB autocompletion: % shows environment variables

Post by admin »

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.)

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: AB autocompletion: % shows environment variables

Post by bdeshi »

[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 ]

Dustydog
Posts: 321
Joined: 13 Jun 2016 04:19

Re: AB autocompletion: % shows environment variables

Post by Dustydog »

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...?

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: AB autocompletion: % shows environment variables

Post by bdeshi »

thanks! and sure, go ahead. (sorry for late reply.)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply