WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: cli-ondemand  (Read 2446 times)

Offline sm8ps

  • Sr. Member
  • ****
  • Posts: 338
cli-ondemand
« on: December 25, 2015, 04:08:19 PM »
As far as I understand, the purpose of ondemand is to give access to extensions through a menu upon demand; that is, the extension should be loaded first if necessary, otherwise it is just launched.

I was wishing that there was something similar on the command line. For instance, I have Vim imported as an extension but I do not want wo have it loaded at boot-time because I do not use it constantly. (Yes, I do admit!  8) ). Yet I always tend to forget to load the extension first before trying to use it which results in a "command not found" error. Simply put, I wanted Vim to launch by typing 'vim' no matter what.

Since it was my birthday, my wishes and wants came true in form of a simple script in '~/.local/bin/cli-ondemand.sh':
Code: [Select]
#!/bin/sh
APPNAME=$(basename $0)
USERPATH=$PATH
NOUSERPATH=$(echo $PATH | cut -d: -f2-)

PATH=$NOUSERPATH
AVAILABLEAPP=$(which $APPNAME)
if [ "$AVAILABLEAPP" = "" ]
then sce-load $APPNAME
fi

APP=$(which $APPNAME)
PATH=$USERPATH
$APP $1

Furthermore, I sym-linked commands of the appropriate name in the same folder to that script:
Code: [Select]
sm@aa1:~/.local/bin$ ls -l
total 4
-rwxr-xr-x 1 sm staff 235 Dez 25 23:49 cli-ondemand.sh
lrwxrwxrwx 1 sm staff  35 Dez 25 23:48 sl -> /home/sm/.local/bin/cli-ondemand.sh
lrwxrwxrwx 1 sm staff  35 Dez 25 23:21 vim -> /home/sm/.local/bin/cli-ondemand.sh

Do you see a better way of reducing the path rather than stripping off the first entry by a hard-coded routine?
Any more comments on how to improve the script?

Cheers!
sm
« Last Edit: December 25, 2015, 04:20:49 PM by sm8ps »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11290
Re: cli-ondemand
« Reply #1 on: December 25, 2015, 04:50:25 PM »
Hi sm8ps
Maybe try adding this to .ashrc:
Code: [Select]
alias sl='cli-ondemand.sh'
alias vim='cli-ondemand.sh'
/home/sm/.local/bin/  is part of the path and will be found without specifying it.

Offline nitram

  • Hero Member
  • *****
  • Posts: 1054
Re: cli-ondemand
« Reply #2 on: December 25, 2015, 05:07:32 PM »
Unless i misunderstood, could simply enter an .ashrc alias for commonly used ondemand item(s), no need for a separate script.

This loads and launches qpdfview from ondemand:
Code: [Select]
alias qpdf='sce-load qpdfview && qpdfview'

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11290
Re: cli-ondemand
« Reply #3 on: December 25, 2015, 05:23:33 PM »
Hi nitram
That depends on what kind of status codes  sce-load  returns. If it returns a failure code when an extension is already
loaded,  qpdf  will not launch the second time you try to invoke it.

Offline nitram

  • Hero Member
  • *****
  • Posts: 1054
Re: cli-ondemand
« Reply #4 on: December 26, 2015, 12:41:05 AM »
Maybe dependent on TC flavour and version. There have been lots of ondemand improvements in later TC 6 forward. In dCore-jessie this launched corebook.pdf back to back using the above alias. First time loads qpdfview and opens file, second time informs qpdfview already installed, then opens corebook.pdf without drama. I suppose if something is wrong with the extension itself then an issue but nothing to do with the alias.
Code: [Select]
tc@box:/mnt/sdb3/stuff$ qpdf corebook.pdf
qpdfview.sce: OK
tc@box:/mnt/sdb3/stuff$ qpdf corebook.pdf
qpdfview is already installed!

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10982
Re: cli-ondemand
« Reply #5 on: December 26, 2015, 09:37:23 AM »
AFAIK it works like that on TC right now. The autogenerated scripts are in path, and with Misalf's changes they even pass any arguments.
The only barriers that can stop you are the ones you create yourself.

Offline Jason W

  • Administrator
  • Hero Member
  • *****
  • Posts: 9730
Re: cli-ondemand
« Reply #6 on: December 26, 2015, 04:24:35 PM »
Porting the new changes in ondemand from the latest TC is on the to do list, lets wait for it before testing the current ondemand in dCore or reporting bugs, etc.

Offline sm8ps

  • Sr. Member
  • ****
  • Posts: 338
Re: cli-ondemand
« Reply #7 on: December 27, 2015, 11:56:16 PM »
Thanks for the input everybody! Using aliases obviously is much simpler than a script.