-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpath_functions
More file actions
57 lines (47 loc) · 1.8 KB
/
path_functions
File metadata and controls
57 lines (47 loc) · 1.8 KB
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
50
51
52
53
54
55
56
57
# -*- mode: shell-script ; coding: utf-8 ; -*-
# path_functions - Shell utility functions for path manipulation and system detection
: "start .path_functions"
# Path manipulation functions
function is_in_path { [[ ":$PATH:" == *":${1:?}:"* ]] ; }
function push_path_var {
test -d "$1" && ! is_in_path "$1" && PATH="$PATH:$1"
}
function unshift_path_var {
test -d "$1" && ! is_in_path "$1" && PATH="$1:$PATH"
}
# Legacy function name for backward compatibility
function path_contains { is_in_path "$@" ; }
# Command existence check
function exists { type "${1}" >/dev/null 2>&1 ; }
# File sourcing utility
function source_if_readable { test -r "$1" && source "$1" ; }
# Shell detection functions
function is_current_bash { test -n "$BASH_VERSION" ; }
function is_current_zsh { test -n "$ZSH_VERSION" ; }
function is_interactive_shell { [[ $- =~ i ]] ; }
if is_current_bash ; then
function is_login_shell { shopt -q login_shell ; }
elif is_current_zsh ; then
function is_login_shell { [[ -o login ]] ; }
fi
function shell_name {
if is_current_bash ; then
echo "bash"
elif is_current_zsh ; then
echo "zsh"
else
echo ""
fi
}
# Platform detection functions
function is_darwin { test "${UNAME:=$(uname)}" = Darwin ; }
function is_linux { test "${UNAME:=$(uname)}" = Linux ; }
function is_cygwin { [[ "${UNAME:=$(uname)}" =~ ^CYGWIN ]] ; }
# Environment detection functions
function is_codespaces { test -n "$CODESPACES" && test "$CODESPACES" = true ; }
function is_kde { test -n "$KDE_FULL_SESSION" && test "$KDE_FULL_SESSION" = true ; }
# Editor detection functions
function is_cursor_local { test -n "$CURSOR_TRACE_ID" ; }
function is_cursor_codespaces { [[ $BROWSER =~ cursor-server ]] ; }
function is_vscode_local { [[ $TERM_PROGRAM == vscode ]] ; }
: "end .path_functions"