yrun - script to run apps

interpretive language scripts


Moderator: Forum moderators

Post Reply
don570
Posts: 624
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 98 times

yrun - script to run apps

Post by don570 »

yrun - script to run apps
written by Ingemar Karlsson

https://yad-guide.ingk.se/examples/exam ... d_examples
yrun is a simple bash script to run an app from a pull down list.
I found that it will run an appimage if the full path is typed in.

yad-run-dropdown.png
yad-run-dropdown.png (11.43 KiB) Viewed 792 times

Code: Select all

#!/bin/bash

XTERM="xterm"

export SCRIPT=$(readlink -f $0)
export PWD=$(dirname $SCRIPT)

# Create history file
mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache}/
export HISTFILE=${XDG_CACHE_HOME:-$HOME/.cache}/ix-run.history

# Create history file
if [ ! -f $HISTFILE ]; then
  mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache}/
  echo "\n" > $HISTFILE
fi

# Delete history file
Clear_History(){
  rm $HISTFILE
  yad --fixed \
    --title="History" \
    --window-icon="applications-system" \
    --text="\n        History Cleared        \n" \
    --timeout="1" \
    --no-buttons
  echo "\n" > $HISTFILE
  kill $YAD_PID
  exec $SCRIPT
}
export -f  Clear_History

# Create and run dialog
TITLE="Run command"
TEXT="\nEnter command to execute:\n"

rcmd=$(yad --entry \
  --width=500 \
  --center \
  --window-icon="gtk-execute" \
  --name="${0##/}" \
  --title="$TITLE" \
  --text="$TEXT" \
  --image="gtk-execute" \
  --editable \
  --rest $HISTFILE \
  --button="Clear History!gtk-clear:bash -c Clear_History" \
  --button="yad-cancel:1" \
  --button="yad-execute:0")

[ -z "$rcmd" ] && exit 0

# Run command
case $rcmd in
  http://*|https://*|ftp://*)
    xdg-open $rcmd &
  ;;
  mailto://*)
    xdg-email $rcmd &
  ;;
  man://*)
    eval $XTERM -e "man ${rcmd#man://}" &
  ;;
  telnet*|ssh*)
    eval $XTERM -e "$rcmd" &
  ;;
  *)
    eval $rcmd &
	;;
esac

# Add command to history
grep -q -F "$rcmd" $HISTFILE || sed -i "1 i $rcmd" $HISTFILE

exit 0
slavvo67
Posts: 5
Joined: Fri Jul 24, 2020 9:31 pm
Been thanked: 1 time

Re: yrun - script to run apps

Post by slavvo67 »

I've been spending much too much of my time creating Docker containers and images. This seems like an interesting alternative to a full desktop in a CLI environment. Wish me luck as I go off and test this baby.

Slavvo67

Post Reply

Return to “Scripts”