Skip to content

Instantly share code, notes, and snippets.

@mingcheng
Created March 24, 2025 01:47
Show Gist options
  • Select an option

  • Save mingcheng/98d38e420940b6f293dba6e391a0fa1c to your computer and use it in GitHub Desktop.

Select an option

Save mingcheng/98d38e420940b6f293dba6e391a0fa1c to your computer and use it in GitHub Desktop.
Replace coreutils by uutils-coreutils in fish shell script
# Check that the uutils are available in the current search paths
if not command -sq uhostid
echo "The uutils are not installed or not in the PATH variable. Adapt the script." >&2
exit 1
end
# --- uutils-coreutils Aliasing ---
# Function to check if uutils command exists
function _uutils_command_exists
set -l cmd $argv[1]
if command -sq "u$cmd"
return 0 # Command exists
else
return 1 # Command does not exist
end
end
# Function to create an alias if the uutils version exists
function _create_uutils_alias
set -l cmd $argv[1]
if _uutils_command_exists $cmd
# Create the alias. Use command to avoid recursion.
alias $cmd="command u$cmd" >&2
else
#echo "Warning: uutils command 'u$cmd' not found. Skipping alias for '$cmd'." >&2
end
end
# --- Aliases (Conditional) ---
# List of coreutils commands to consider. Expand this as needed.
set -l uutils_commands = (ls (brew --prefix)/opt/uutils-coreutils/libexec/uubin)
# Create the aliases, checking for existence first.
for cmd in $uutils_commands
# dot forget to avoid creating an alias for the test command
if test (string length "$cmd") -gt 1; and test "$cmd" != test
_create_uutils_alias $cmd
end
end
# --- Helper function to easily disable/enable uutils aliases ---
function disable_uutils_aliases
for cmd in $uutils_commands
if functions -q $cmd; and string match -q 'command u*' (functions $cmd | string split ' ')[2]
functions --erase $cmd
echo "Disabled alias for: $cmd"
end
end
end
function enable_uutils_aliases
for cmd in $uutils_commands
_create_uutils_alias $cmd
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment