-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_bash_functions
49 lines (40 loc) · 1.25 KB
/
dot_bash_functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# SPDX-FileCopyrightText: Chris Wilson <[email protected]>
#
# SPDX-License-Identifier: MIT
# Shell functions for Bash shells
# shellcheck shell=bash
# ------------------------------------------------------------------------------
# Source shell functions
# ------------------------------------------------------------------------------
if [[ -r "${HOME}/.sh_functions" ]]; then
# shellcheck source=dot_sh_functions
. "${HOME}/.sh_functions"
fi
# ------------------------------------------------------------------------------
# Functions
# ------------------------------------------------------------------------------
# Is this shell a login shell?
is_login_shell ()
{
shopt -q login_shell
}
# Is this shell an interactive shell?
# https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html
is_interactive_shell ()
{
[[ $- == *i* ]]
}
# Is this command a specific type? e.g. if is_type ll alias; then ... fi
# https://stackoverflow.com/a/85903
is_type ()
(
arg_type=$(type -t "${1}")
[[ -n "${arg_type}" ]] && [[ "${arg_type}" == "${2}" ]]
)
# Does this function exist?
# This is faster than using is_type
# https://stackoverflow.com/a/85932
function_exists ()
{
declare -F "$1" > /dev/null
}