Tiny Core Linux

dCore Import Debian Packages to Mountable SCE extensions => dCore X86 => Topic started by: sm8ps on December 25, 2015, 07:08:19 PM

Title: cli-ondemand
Post by: sm8ps on December 25, 2015, 07: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
Title: Re: cli-ondemand
Post by: Rich on December 25, 2015, 07: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.
Title: Re: cli-ondemand
Post by: nitram on December 25, 2015, 08: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'
Title: Re: cli-ondemand
Post by: Rich on December 25, 2015, 08: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.
Title: Re: cli-ondemand
Post by: nitram on December 26, 2015, 03: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!
Title: Re: cli-ondemand
Post by: curaga on December 26, 2015, 12:37:23 PM
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.
Title: Re: cli-ondemand
Post by: Jason W on December 26, 2015, 07: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.
Title: Re: cli-ondemand
Post by: sm8ps on December 28, 2015, 02:56:16 AM
Thanks for the input everybody! Using aliases obviously is much simpler than a script.