Skip to content

Instantly share code, notes, and snippets.

function dirname {
local names=() delim='\n' n x
local VERSION=0.1
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
echo "Usage: dirname [OPTIONS] [--] NAME ...
Removes the last non-slash component from NAME and the slashes that
@konsolebox
konsolebox / mapfile.bash
Last active January 7, 2022 23:00
Provides a function that emulates bash 5.0's mapfile
#!/bin/bash
shopt -s extglob
[[ BASH_VERSINFO -ge 5 ]] && set -u
#### Implementation Snippet Begins ####
function mapfile.error {
printf '%s\n' "$1" "$@"
exit "${2-1}"
}
diff --git a/src/utils_password.c b/src/utils_password.c
index 58f3a7b..5a055a8 100644
--- a/src/utils_password.c
+++ b/src/utils_password.c
@@ -106,33 +106,60 @@ static int tools_check_password(const char *password)
/* Password reading helpers */
-static ssize_t read_tty_eol(int fd, char *pass, size_t maxlen)
+static ssize_t read_tty_eol(int fd, int ofd, char *pass, size_t maxlen)
function compare_versions {
local a=${1%%.*} b=${2%%.*}
[[ "10#${a:-0}" -gt "10#${b:-0}" ]] && return 1
[[ "10#${a:-0}" -lt "10#${b:-0}" ]] && return 2
a=${1:${#a} + 1} b=${2:${#b} + 1}
[[ -z $a && -z $b ]] || compare_versions "$a" "$b"
}
...
function get_opt_and_optarg {
local optional=false
if [[ $1 == @optional ]]; then
optional=true
shift
fi
shopt -s extglob
function grep.fail {
printf '%s\n' "$1" >&2
exit "${2-1}"
}
function grep.get_opt_and_optarg {
OPT=$1 OPTARG= OPTSHIFT=0
#!/usr/bin/env ruby
require 'find'
Find.find('.')
.inject({}) do |hash, path|
base = path.gsub(/.*\//, '')
(hash[base] ||= []) << path unless base.empty?
hash
end
#!/bin/bash
# Based on https://askubuntu.com/a/571711/415750
function main {
local screen_width screen_height WIDTH HEIGHT new_pos_x new_pos_y
read screen_width screen_height < <(xdotool getactivewindow getdisplaygeometry)
eval "$(xdotool getactivewindow getwindowgeometry --shell | grep -e WIDTH= -e HEIGHT=)"
new_pos_x=$(( screen_width / 2 - WIDTH / 2 ))
new_pos_y=$(( screen_height / 2 - HEIGHT / 2 ))
#!/bin/bash
# ----------------------------------------------------------------------
# sudodir
#
# Executes command as owner of current directory.
#
# It also calls xhost to give owner access to X if user allows it.
#
diff --git a/libs/core.bash.in b/libs/core.bash.in
index 2800cc5..a3791ba 100644
--- a/libs/core.bash.in
+++ b/libs/core.bash.in
@@ -113,6 +113,9 @@ do_action() {
|| die -q "Action ${subaction} unknown"
check_do "do_${subaction}" "$@"
fi
+ if [[ $? -eq 0 && -e /etc/eselect/hooks/${ESELECT_MODULE_NAME}/${subaction} ]]; then
+ source "/etc/eselect/hooks/${ESELECT_MODULE_NAME}/${subaction}"