/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1
22 by Gustav Hartvigsson
* useful.inc.sh
1
#!/usr/bin/env bash
2
3
####
4
# FILE NAME useful.inc.sh
27 by Gustav Hartvigsson
Added copyright information to all files.
5
#
6
# Authors:
7
#    Gustav Hartvigsson 2024
8
#    Distributed under the Cool Licence 1.1
22 by Gustav Hartvigsson
* useful.inc.sh
9
# 
10
# PURPOSE
11
#   This file provides usefule bash libary functions.
12
####
13
# Add the following to your script to be able to include it:
14
#     __SCRIPT_ROOT=$(dirname $(readlink -f $0))
15
#     source $__SCRIPT_ROOT/useful.inc.sh
16
####
17
18
####
19
# FUNCTION __silent
20
#
21
# PURPOSE
22
#   Silent a run command.
23
#
24
# ARGUMENTS
25
#   A command and it's arguments.
26
#
27
# RETURNS
28
#   Exit code of command.
29
#
30
####
31
function __silent () {
32
  $@ >> /dev/null 2>&1
33
  return $?
34
}
35
36
####
37
# FUNCTION __find_tool
38
#
39
# PURPOSE
40
#   checks if a tool (progam) exists.
41
#
42
# NOTE
43
#   You need to specify "__SANITY=true" among your globals.
44
####
45
function __find_tool () {
46
  __silent which $1
47
48
  if [[ $? > 0 ]]; then
49
    echo "    Can't find tool \"${1}\"."
50
    __SANITY=false
51
  fi
52
}