#!/bin/sh # The MIT License (MIT) # # Copyright © 2020-2025 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the “Software”), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # tldr [options...] [tools...] # # # Lookup examples from the `tldr` set, showing how to use command-line tools. # When not given options to look into OS-specific entries, all entries are # looked-up from the `common` set. # # # Options, also available starting with double-dashes # # -f look only for freebsd-specific entries # -freebsd look only for freebsd-specific entries # # -h show this help message # -help show this help message # # -l look only for linux-specific entries # -linux look only for linux-specific entries # # -m look only for macos-specific entries # -macos look only for macos-specific entries # # -o look only for openbsd-specific entries # -openbsd look only for openbsd-specific entries # # -w look only for windows-specific entries # -win look only for windows-specific entries # -windows look only for windows-specific entries case "$1" in -h|--h|-help|--help) awk '/^# +tldr /, /^$/ { gsub(/^# ?/, ""); print }' "$0" exit 0 ;; -f|--f|-freebsd|--freebsd) kind="freebsd" shift ;; -l|--l|-linux|--linux) kind="linux" shift ;; -m|--m|-mac|--mac|-macos|--macos|-macosx|--macosx|-osx|--osx) kind="osx" shift ;; -o|--o|-openbsd|--openbsd) kind="openbsd" shift ;; -w|--w|-win|--win|-windows|--windows) kind="windows" shift ;; --) shift;; -*) kind="$(echo "$1" | sed -E 's/--?//')" shift ;; esac if [ $# -eq 0 ]; then awk '/^# +tldr /, /^$/ { gsub(/^# ?/, ""); print }' "$0" exit 1 fi base='https://raw.githubusercontent.com/tldr-pages/tldr/main/pages' kind="${kind:-common}" options="-MKiCRS" if [ $# -eq 1 ]; then options="-MKiCRS --header=1" fi got=0 for arg in "$@"; do [ "${got}" -gt 0 ] && printf "\n" got=1 if echo "${arg}" | grep -q -v / ; then arg="${kind}/${arg}" fi printf "\e[7m%-80s\e[0m\n" "${arg}" curl -s --show-error "${base}/${arg}.md" 2>&1 | awk ' NR == 1 && /^404: / { printf "\x1b[38;2;204;0;0m%s\x1b[0m\n", $0; next } NR <= 2 || /^>/ { printf "\x1b[38;2;164;164;164m%s\x1b[0m\n", $0; next } /^`/ { printf "\x1b[48;2;224;224;224m%s\x1b[0m\n", $0; next } 1 ' done | less "${options}"