Article
Joel Solon · Dec 30, 2021 1m read

Did you know that IRIS Terminal could do this?!?! History and Aliases!

Hi all,

When is a Developer Community post not a Developer Community post? When it's just a few sentences wrapped around a link to InterSystems documentation! And what better way to finish up 2021 than by telling you about something cool that's been available since v2020.3? As the ball drops in Times Square, curl up with this:

Repeating Previous Commands

I think it will bring you joy! Post your favorite aliases below. Happy New Year!

9
0 446
Discussion (26)5
Log in or sign up to continue

:alias sql do $system.SQL.Shell()

:alias err do $system.Status.DisplayError($1)

Thanks Joel! I saw it in early previews and I didn't realize there were already these shorcuts... perhaps they weren't there yet.

One question... how could we save the alias we have defined so to "import" and use them in other instances?

I like :sql as a way to launch the shell - so that means this alias should be renamed to something else!!

USER>:sql "select top 2 * from person"
do $system.SQL.Execute("select top 2 * from person").%Display()
id    name    ssn    dob    home_street    home_city    home_state    home_zip
1    Willeke,Thelma K.    934-46-2099    18948    308 Madison Blvd    Bensonhurst    HI    71501
2    Nathanson,Will P.    771-91-1008    37359    9664 Second Place    Jackson    VA    15837

2 Rows(s) Affected

I have one older IRIS instance (unreleased v2021.1 with some Python extras) that has the following aliases built in. The :sql alias doesn't run Execute() like it seems to do on yours.

:py          Do $system.Python.Shell()
:mdx         Do $system.DeepSee.Shell()
:sql         Do $system.SQL.Shell()
:tsql        Do $system.SQL.TSQLShell()

That's because I defined that alias myself - on Linux it is the .iris_init file in my home directory. I don't know where that is on Windows...

Ah, I misinterpreted "this alias" in your post! So you meant (I added italicized text): "I like to define :sql as a way to launch the shell and execute a statement - so that means this built-in :sql alias should be renamed by InterSystems to something else!! or be removed."

At least aliases defined in .iris_init override any built-in aliases.

Not quite - I just defined that alias this morning to test something out. I think that a pre-defined (shipped with Iris) sql alias should launch the shell - I didn't know anything about pre-installed/shipped with Iris aliases.

Cool.

I use custom ObjectScript commands via ^%ZLANG Routines.

Advantages:

  • Crossplatform
  • Easy to transfer between servers
  • Available since times immemorial

Post your favorite aliases below.  

SQL shorthand is definitely useful.

Hi Joel, is there any way to persist aliases from session to session? 

Perhaps a ZPM package that sets all up can help?

Thanks, Evgeny. Do you have a sample/example of how that might be done?

Honestly have no idea ) It's was just thought between NY salads eating) But I bet @Robert C. Cemper or @Dmitry Maslennikov could suggest something. I bet Terminal saves aliases in some global that could be investigated. It's a hack of course thus not recommended officially until we document the global.

If you use Docker for development with IRIS this could be easier. E.g. we could run the terminal program(what is it BTW?) during the iris.script phase and setup aliases of taste.

Hi! though this looks like a nice feature it is not so useful if not portable and
even available in ZPM.
I use since ~ever~  my 3..5 char abbreviated extensions in %ZLANG...*
to add such abbreviations I have even created my helper to add it o the fly
Helper for ObjectScript Language Extensions with OEX + Video

And sorry where is the difference between :sql  to ZSQL or zsql  (insensible to any mix of case) ?
In addition in %ZLANG* your shortcut can also be a multiline function. 
 

It looks like, it already persists somehow. I'm using docker, after halt command, I've entered the same container back with session, looked at :h and is history there, as well as aliases.

Nope, aliases not persisted, but :sql, :s works as SQL Shell without aliasing it

Hmm. :sql or :s does not seem to work for me without actually creating an alias. I'm currently testing this with HealthShare, $ZV = IRIS for Windows (x86-64) 2021.1 (Build 215_0_21260U) Tue Nov 9 2021 19:30:33 EST. Maybe a 2021.2 feature?

docker exec -it iris iris session iris

Node: fa3f20fc42dc, Instance: IRIS

USER>w $zv
IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2021.2 (Build 617U) Thu Dec 9 2021 15:00:18 UTC
USER>:c

USER>:h
 1: :h

USER>:a

USER>:sql
SQL Command Line Shell
----------------------------------------------------

The command prefix is currently set to: <<nothing>>.
Enter <command>, 'q' to quit, '?' for help.
[SQL]USER>>  << entering multiline statement mode, 'GO' to execute >>
    1>>q
[SQL]USER>>q

USER>:t
SQL Command Line Shell
----------------------------------------------------

The command prefix is currently set to: <<nothing>>.
Enter <command>, 'q' to quit, '?' for help.

dialect = MSSQL
[SQL]USER>>

even :t for TSQL dialect

Node: Krusty, Instance: HEALTHSHARE
 
Username: jeff
Password: ****
USER>:c
 
USER>:h
 1: :h
 
USER>:a
 
USER>:sql
>> Invalid history command
 
USER>:t
>> Invalid history command
 
USER>w $ZV
IRIS for Windows (x86-64) 2021.1 (Build 215_0_21260U) Tue Nov 9 2021 19:30:33 EST

Maybe you're seeing a 2021.2 behavior.

Or it's just this docker thing the cool kids use ... wink

To get a list of the built-in aliases, try ":?", this is from 2021.1 for example:

USER>:?       
 :<number>    Recall command # <number>
 :?           Display help
 :alias       Create/display aliases
 :clear       Clear history buffer
 :history     Display command history
 :unalias     Remove aliases

Note how indeed we don't have :sql in the 2021.1 release, it came later..

Here's some info that was inadvertently removed from the docs, but will be returning soon:


On Unix systems, if a file named ~/.iris_init exists, it is read when a terminal session is initiated. Only lines starting with :<command> are processed. All other lines are ignored. This file accepts only :alias commands, which enables you to store favorite command abbreviations there.
Example of a ~/.iris_init file:

# Initial aliases
:alias %  zn "%SYS"
:alias load Do $System.OBJ.Load("$1",$S("$2"="":"ck",1:"$2"))
:alias ut Do ##class(%UnitTest.Manager).RunTest("$1")

Now just needs to be a way to "import it"/"preserve"/"make it easier" in Windows systems, to cover the other 70% of people. wink

You Windows users have scripting ...

wait for: Username:
send: username<CR>
wait for: Password:
send: password<CR>
send: :alias sql Do $system.SQL.Shell()<CR>
send: :alias % zn "%SYS"<CR>

Save the script to a file with an .scr extension, and start terminal with:

\path\to\iristerm.exe /console=cn_iptcp:hostname[port] \path\to\scriptname.scr

Yep, I know. But I hoped something more "transparent"... if we deal with several instances and change with certain frecuency (as it's my case), having to define direct accesses when we have a link in the "cube" menu, doesn't seem too clean. For Linux/Mac users, the solution is clean. You just define your aliases file, and you just can install your IRIS instances... all of them would make use of them seamlessly... that's the functionality. Right now, for windows users, it's incomplete. A pity because it's a really very good feature to have, our terminal/shell needs these kind of tools, but it has to be much easier to reuse among instances.  IMHO. 

Perhaps it would be as easy as to change our installer so to include that argument out-of-the-box in the call to Terminal in the cube... and then let the developers build their own script in their own home directory.