Small execute helper for the terminal

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Post Reply
Message
Author
User avatar
thomasl
Posts: 414
Joined: Sun Feb 04, 2018 10:26 am

Small execute helper for the terminal

#1 Post by thomasl »

This script was among the first bits I adapted from my Windows console helpers. It's basically for those who do a lot of work in a terminal (window). I've stored the script in a file called x (also setting its executable bit) so that I can do these things (and probably some more):

Code: Select all

$x                         # opens a fresh terminal window
$x xyz.html                # opens html page in default browser
$x http://some.web.site    # opens website
$x some.pdf                # opens pdf in registered pdf viewer
$x some.jpg                # opens image in registered image viewer
# etc for other file types...
$x /this/folder            # opens /this.folder in file manager
$x some.executable         # runs some.executable in the background (good for GUI stuff producing many warnings in the terminal)
It doesn't handle everything but it saves some typing and the odd excursion to the file manager... ;)

Code: Select all

#!/bin/bash
if [[ -z $1 ]]; then
	xfce4-terminal
elif [[ -d $1 || $1 =~ https?:// || -z $(whereis -b "$1" | cut -sd: -f2) ]]; then
	if [[ -f $1 && -x $1 ]]; then
		"$@" >/dev/null 2>&1 &
	else
		xdg-open "$@" >/dev/null 2>&1
	fi
else
	"$@" >/dev/null 2>&1 &
fi
Frugal installs on Lenovo ThinkPad L14 Ryzen 5 4650U/24GB * HP Pavilion Ryzen 3 3300U/16GB * Toshiba R950 i5-3340M/12GB
I have a reservation... What do you mean it's not in the COMPUTER!

Post Reply

Return to “Tips & Tricks by users”