Compare commits
4 Commits
84e6fdd429
...
b79103a0a6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b79103a0a6 | ||
|
|
e5bafe1721 | ||
|
|
322d03ed4c | ||
|
|
60a159c3ea |
@@ -93,7 +93,7 @@ utaz()
|
|||||||
unarj e "$1" "$2/" >/dev/null 2>&1
|
unarj e "$1" "$2/" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
_unlza()
|
_unlha()
|
||||||
{
|
{
|
||||||
# lha typically extracts into the current directory
|
# lha typically extracts into the current directory
|
||||||
# We ensure it hits the target directory
|
# We ensure it hits the target directory
|
||||||
@@ -546,7 +546,7 @@ taz()
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
-[1-9])
|
-[1-9])
|
||||||
compression="${1#-}"
|
complevel="${1#-}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
|
|||||||
@@ -148,7 +148,8 @@ export -f isipv6
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Encode a string so it can be used as a URL parameter
|
# Encode a string so it can be used as a URL parameter
|
||||||
# Usage: urlencode <string>
|
# Usage: urlencode <string>
|
||||||
urlencode() {
|
urlencode()
|
||||||
|
{
|
||||||
local LANG=C
|
local LANG=C
|
||||||
local str="$*"
|
local str="$*"
|
||||||
local length="${#str}"
|
local length="${#str}"
|
||||||
@@ -177,7 +178,8 @@ export -f urlencode
|
|||||||
# -c, --coord Display only the coordinates (latitude, longitude)
|
# -c, --coord Display only the coordinates (latitude, longitude)
|
||||||
# -a, --as Display only the Autonomous System (AS) information
|
# -a, --as Display only the Autonomous System (AS) information
|
||||||
# -R, --raw Display raw JSON response
|
# -R, --raw Display raw JSON response
|
||||||
myextip() {
|
myextip()
|
||||||
|
{
|
||||||
local show_ip=false show_isp=false show_loc=false
|
local show_ip=false show_isp=false show_loc=false
|
||||||
local show_coord=false show_as=false show_raw=false
|
local show_coord=false show_as=false show_raw=false
|
||||||
local all=true
|
local all=true
|
||||||
@@ -236,7 +238,7 @@ myextip() {
|
|||||||
|
|
||||||
# Fetch data. Allow overriding endpoint via env var MYEXTIP_URL
|
# Fetch data. Allow overriding endpoint via env var MYEXTIP_URL
|
||||||
local MYEXTIP_URL
|
local MYEXTIP_URL
|
||||||
MYEXTIP_URL=${MYEXTIP_URL:-http://ip-api.com/json/}
|
MYEXTIP_URL=${MYEXTIP_URL:-https://ip-api.com/json/}
|
||||||
|
|
||||||
local response
|
local response
|
||||||
if ! response=$(dwl "$MYEXTIP_URL"); then
|
if ! response=$(dwl "$MYEXTIP_URL"); then
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
# Protected by the BSD3 license. Please read bellow for details.
|
# Protected by the BSD3 license. Please read bellow for details.
|
||||||
#
|
#
|
||||||
# * Redistribution and use in source and binary forms,
|
# * Redistribution and use in source and binary forms,
|
||||||
@@ -50,7 +50,27 @@ ppg()
|
|||||||
disp E "Usage: ppg <string>"
|
disp E "Usage: ppg <string>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
ps -edf | grep "$@" | grep -v "grep $@"
|
|
||||||
|
local pattern="$*"
|
||||||
|
|
||||||
|
if command -v pgrep >/dev/null 2>&1; then
|
||||||
|
pgrep -af -- "$pattern"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
ps -ef | awk -v pattern="$pattern" '
|
||||||
|
NR == 1 {
|
||||||
|
print
|
||||||
|
next
|
||||||
|
}
|
||||||
|
index($0, pattern) {
|
||||||
|
print
|
||||||
|
matched = 1
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
exit matched ? 0 : 1
|
||||||
|
}
|
||||||
|
'
|
||||||
}
|
}
|
||||||
export -f ppg
|
export -f ppg
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -123,17 +143,42 @@ gpid()
|
|||||||
disp E "Usage: gpid <process_name [process_name2 ...]>"
|
disp E "Usage: gpid <process_name [process_name2 ...]>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
[[ $UID -eq 0 ]] && local psopt="-A"
|
local single=0
|
||||||
[[ $# -eq 1 ]] && local single=1
|
local found=0
|
||||||
for pid in $@; do
|
local proc_name result
|
||||||
local result=$(ps $psopt | grep $pid | awk '{print $1}' | sed "s/\n/ /")
|
|
||||||
if [[ $single ]]; then
|
[[ $# -eq 1 ]] && single=1
|
||||||
[[ $result ]] && echo "${result//$'\n'/ }"
|
|
||||||
|
for proc_name in "$@"; do
|
||||||
|
result=""
|
||||||
|
|
||||||
|
if command -v pgrep >/dev/null 2>&1; then
|
||||||
|
result=$(pgrep -d ' ' -x -- "$proc_name")
|
||||||
else
|
else
|
||||||
[[ $result ]] && echo "$pid: ${result//$'\n'/ }"
|
result=$(ps -eo pid=,comm= | awk -v proc="$proc_name" '
|
||||||
|
$2 == proc {
|
||||||
|
if (out != "") {
|
||||||
|
out = out " "
|
||||||
|
}
|
||||||
|
out = out $1
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
print out
|
||||||
|
}
|
||||||
|
')
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -z "$result" ]] && continue
|
||||||
|
|
||||||
|
found=1
|
||||||
|
if (( single )); then
|
||||||
|
echo "$result"
|
||||||
|
else
|
||||||
|
echo "$proc_name: $result"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
[[ $result ]] || return 1
|
|
||||||
|
(( found )) || return 1
|
||||||
}
|
}
|
||||||
export -f gpid
|
export -f gpid
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -155,8 +200,14 @@ ku()
|
|||||||
disp E "Usage: ku <username1 [username2 ...]>"
|
disp E "Usage: ku <username1 [username2 ...]>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
for u in $@; do
|
local users="$@"
|
||||||
|
for u in $users; do
|
||||||
|
if ! id "$u" >/dev/null 2>&1; then
|
||||||
|
disp E "User '$u' does not exist."
|
||||||
|
return 1
|
||||||
|
else
|
||||||
killall -u "$u"
|
killall -u "$u"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f ku
|
export -f ku
|
||||||
@@ -187,14 +238,16 @@ kt()
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
children_pids=$(pgrep -P "$parent_pid")
|
local children_pids=$(pgrep -P "$parent_pid")
|
||||||
|
|
||||||
for pid in $children_pids; do
|
for pid in $children_pids; do
|
||||||
kt "$pid" "$@" || break
|
kt "$pid" "$@" || break
|
||||||
done
|
done
|
||||||
kill "$@" "$parent_pid"
|
kill "$@" "$parent_pid"
|
||||||
}
|
}
|
||||||
|
export -f kt
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|
||||||
|
|||||||
47
profile.sh
47
profile.sh
@@ -52,30 +52,42 @@ fi
|
|||||||
# path* : private functions for PATH variable management
|
# path* : private functions for PATH variable management
|
||||||
pathremove()
|
pathremove()
|
||||||
{
|
{
|
||||||
|
[[ -z "$1" ]] && return 0
|
||||||
local IFS=':'
|
local IFS=':'
|
||||||
local newpath
|
local newpath dir
|
||||||
local dir
|
local pathvar="${2:-PATH}"
|
||||||
local pathvar=${2:-PATH}
|
[[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || {
|
||||||
|
printf "pathremove: unsafe variable name '%s'\n" "$pathvar" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
for dir in ${!pathvar}; do
|
for dir in ${!pathvar}; do
|
||||||
if [ "$dir" != "$1" ]; then
|
[[ "$dir" != "$1" ]] && newpath="${newpath:+$newpath:}$dir"
|
||||||
newpath=${newpath:+$newpath:}$dir
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
export $pathvar="$newpath"
|
export "$pathvar=$newpath"
|
||||||
}
|
}
|
||||||
|
|
||||||
pathprepend()
|
pathprepend()
|
||||||
{
|
{
|
||||||
pathremove $1 $2
|
[[ -z "$1" ]] && return 0
|
||||||
local pathvar=${2:-PATH}
|
local pathvar="${2:-PATH}"
|
||||||
export $pathvar="$1${!pathvar:+:${!pathvar}}"
|
[[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || {
|
||||||
|
printf "pathprepend: unsafe variable name '%s'\n" "$pathvar" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
pathremove "$1" "$pathvar"
|
||||||
|
export "$pathvar=$1${!pathvar:+:${!pathvar}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
pathappend()
|
pathappend()
|
||||||
{
|
{
|
||||||
pathremove $1 $2
|
[[ -z "$1" ]] && return 0
|
||||||
local pathvar=${2:-PATH}
|
local pathvar="${2:-PATH}"
|
||||||
export $pathvar="${!pathvar:+${!pathvar}:}$1"
|
[[ "$pathvar" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || {
|
||||||
|
printf "pathappend: unsafe variable name '%s'\n" "$pathvar" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
pathremove "$1" "$pathvar"
|
||||||
|
export "$pathvar=${!pathvar:+${!pathvar}:}$1"
|
||||||
}
|
}
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -223,11 +235,14 @@ load_conf system # Load Bash system behavior configuration (history, pager, etc
|
|||||||
load_conf general # General purpose configuration (compilation flags, etc.)
|
load_conf general # General purpose configuration (compilation flags, etc.)
|
||||||
|
|
||||||
# Load module scripts
|
# Load module scripts
|
||||||
for script in $MYPATH/profile.d/*.sh; do
|
shopt -s nullglob
|
||||||
if [[ -r $script ]]; then
|
for script in "$MYPATH/profile.d/"*.sh; do
|
||||||
. $script
|
if [[ -f "$script" && -r "$script" ]]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$script" || printf "[ Warning ] Failed to source module: %s\n" "$script" >&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
# Interactive shell detection, two methods available each one of those might have different result
|
# Interactive shell detection, two methods available each one of those might have different result
|
||||||
# depending on distribution
|
# depending on distribution
|
||||||
|
|||||||
Reference in New Issue
Block a user