/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1

« back to all changes in this revision

Viewing changes to scripts/useful.inc.sh

  • Committer: Gustav Hartvigsson
  • Date: 2024-11-02 21:19:08 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241102211908-ad9nwyj2sf3mpepv
* That's awkard...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
 
 
3
####
 
4
# FILE NAME useful.inc.sh
 
5
#
 
6
# Authors:
 
7
#    Gustav Hartvigsson 2024
 
8
#    Distributed under the Cool Licence 1.1
 
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
export -f __silent
 
37
 
 
38
####
 
39
# FUNCTION __find_tool
 
40
#
 
41
# PURPOSE
 
42
#   checks if a tool (progam) exists.
 
43
#
 
44
# NOTE
 
45
#   You need to specify "__SANITY=true" among your globals.
 
46
####
 
47
function __find_tool () {
 
48
  __silent which $1
 
49
 
 
50
  if [[ $? > 0 ]]; then
 
51
    echo "    Can't find tool \"${1}\"."
 
52
    __SANITY=false
 
53
  fi
 
54
}
 
55
 
 
56
export -f __find_tool