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!
). 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':
#!/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:
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