There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Custom, interoperable info and man commands

Source code


<span style="color:#323232;">#!/usr/bin/env bash
</span><span style="color:#323232;">
</span><span style="color:#323232;"># get the texinfo node for a command
</span><span style="color:#323232;"># - takes a command name, like 'cat'
</span><span style="color:#323232;"># - if it belongs to a texinfo node, returns the node name, like 'coreutils' 
</span><span style="color:#323232;"># - otherwise returns empty string
</span><span style="color:#323232;">function __get_texinfo_node_for_command () {
</span><span style="color:#323232;">  local coreutils_commands=(
</span><span style="color:#323232;">    'cat' 'tac' 'nl' 'od' 'base32' 'base64' 'base64' 'basenc'
</span><span style="color:#323232;">    'fmt' 'pr' 'fold' 
</span><span style="color:#323232;">    'head' 'tail' 'split' 'csplit'  
</span><span style="color:#323232;">    'wc' 'sum' 'cksum' 'b2sum' 'md5sum' 'sha1sum'    
</span><span style="color:#323232;">    'sha224sum' 'sha256sum' 'sha384sum' 'sha512sum'
</span><span style="color:#323232;">    'sort' 'shuf' 'uniq' 'comm' 'ptx' 'tsort' 'ptx'
</span><span style="color:#323232;">    'cut' 'paste' 'join'
</span><span style="color:#323232;">    'tr' 'expand' 'unexpand'
</span><span style="color:#323232;">    'ls' 'dir' 'vdir' 'dircolors'
</span><span style="color:#323232;">    'cp' 'dd' 'install' 'mv' 'rm' 'shred'
</span><span style="color:#323232;">    'link' 'ln' 'mkdir' 'mkfifo' 'mknod' 'readlink' 'rmdir' 'unlink'
</span><span style="color:#323232;">    'chown' 'chgrp' 'chmod' 'touch'
</span><span style="color:#323232;">    'df' 'du' 'stat' 'sync' 'truncate'
</span><span style="color:#323232;">    'echo' 'printf' 'yes'
</span><span style="color:#323232;">    'false' 'true' 'test' 'expr' 'tee'
</span><span style="color:#323232;">    'basename' 'dirname' 'pathchk' 'mktemp' 'realpath'
</span><span style="color:#323232;">    'pwd' 'stty' 'printenv' 'tty'
</span><span style="color:#323232;">    'id' 'logname' 'whoami' 'groups' 'users' 'who'
</span><span style="color:#323232;">    'arch' 'date' 'nping' 'uname' 'hostname' 'hostid' 'uptime'
</span><span style="color:#323232;">    'chcon' 'runcon'
</span><span style="color:#323232;">    'chroot' 'env' 'nice' 'nohup' 'stdbuf' 'timeout'
</span><span style="color:#323232;">    'kill' 'sleep'
</span><span style="color:#323232;">    'factor' 'numfmt' 'seq' 
</span><span style="color:#323232;">  )
</span><span style="color:#323232;">
</span><span style="color:#323232;">  local bash_builtins=(
</span><span style="color:#323232;">    '.' ':' '[' 'alias' 'bg' 'bind' 'break' 'builtin' 'caller' 'cd' 'command'
</span><span style="color:#323232;">    'compgen' 'complete' 'compopt' 'continue' 'declare' 'dirs' 'disown' 'echo'
</span><span style="color:#323232;">    'enable' 'eval' 'exec' 'exit' 'export' 'false' 'fc' 'fg' 'getopts' 'hash'
</span><span style="color:#323232;">    'help' 'history' 'jobs' 'kill' 'let' 'local' 'logout' 'mapfile' 'popd'
</span><span style="color:#323232;">    'printf' 'pushd' 'pwd' 'read' 'readarray' 'readonly' 'return' 'set'
</span><span style="color:#323232;">    'shift' 'shopt' 'source' 'suspend' 'test' 'times' 'trap' 'type' 'typeset'
</span><span style="color:#323232;">    'ulimit' 'umask' 'unalias' 'unset' 'wait'
</span><span style="color:#323232;">
</span><span style="color:#323232;">    # and some reserved words too:
</span><span style="color:#323232;">    '!' # this represents pipelines
</span><span style="color:#323232;">    '[[' '{' 'case' 'if' 'for' 'function' 'select' 'time' 'until' 'while'
</span><span style="color:#323232;">  )
</span><span style="color:#323232;">  
</span><span style="color:#323232;">  for cmd in "${bash_builtins[@]}"; do
</span><span style="color:#323232;">    if [[ "$1" == "$cmd" ]]; then
</span><span style="color:#323232;">      echo 'bash'
</span><span style="color:#323232;">      return 0
</span><span style="color:#323232;">    fi
</span><span style="color:#323232;">  done
</span><span style="color:#323232;">  for cmd in "${coreutils_commands[@]}"; do
</span><span style="color:#323232;">    if [[ "$1" == "$cmd" ]]; then
</span><span style="color:#323232;">      echo 'coreutils'
</span><span style="color:#323232;">      return 0
</span><span style="color:#323232;">    fi
</span><span style="color:#323232;">  done
</span><span style="color:#323232;">
</span><span style="color:#323232;">  echo ''
</span><span style="color:#323232;">  return 0
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;"># custom info
</span><span style="color:#323232;"># - prepend 'coreutils' if argument is a coreutils command
</span><span style="color:#323232;"># - prepend 'bash' if argument is a bash builtin
</span><span style="color:#323232;"># - add some default options
</span><span style="color:#323232;">function info () {
</span><span style="color:#323232;">  # if there is only one non-option argument, and it matches a coreutils or
</span><span style="color:#323232;">  # bash builtin, prepend the corresponding name
</span><span style="color:#323232;">  local option_args=()
</span><span style="color:#323232;">  local non_option_args=()
</span><span style="color:#323232;">  for arg in "$@"; do
</span><span style="color:#323232;">    if [[ ! "$arg" =~ ^- ]]; then
</span><span style="color:#323232;">      non_option_args+=("$arg")
</span><span style="color:#323232;">    else
</span><span style="color:#323232;">      option_args+=("$arg")
</span><span style="color:#323232;">    fi
</span><span style="color:#323232;">  done
</span><span style="color:#323232;">  if [[ "${#non_option_args[@]}" -eq 1 ]]; then
</span><span style="color:#323232;">    info_node="$(__get_texinfo_node_for_command "${non_option_args[0]}")"
</span><span style="color:#323232;">    if [[ -n "$info_node" ]]; then
</span><span style="color:#323232;">        non_option_args=("${info_node}" "${non_option_args[@]}")
</span><span style="color:#323232;">    fi
</span><span style="color:#323232;">  fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # add default options and run
</span><span style="color:#323232;">  option_args+=('--vi-keys' '--init-file' "${XDG_CONFIG_HOME}/infokey")
</span><span style="color:#323232;">  command info "${option_args[@]}" "${non_option_args[@]}"
</span><span style="color:#323232;">}
</span><span style="color:#323232;">alias i="info"
</span><span style="color:#323232;">
</span><span style="color:#323232;"># custom man
</span><span style="color:#323232;"># - if receiving a command with info page, run info instead
</span><span style="color:#323232;">function man () {
</span><span style="color:#323232;">  if [[ "$#" -eq 1 &amp;&amp; $(__get_texinfo_node_for_command "$1") != '' ]]; then
</span><span style="color:#323232;">    info "$1"
</span><span style="color:#323232;">  else
</span><span style="color:#323232;">    command man "$1"
</span><span style="color:#323232;">  fi
</span><span style="color:#323232;">}
</span><span style="color:#323232;">alias m="man"
</span>
  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines