this post was submitted on 13 Aug 2024
19 points (95.2% liked)

Linux

48067 readers
701 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

You can use cheat sh web service to show cheatsheets for all kind of commands. Just replace the command name: curl -s cheat.sh/date. I also wrote a a simple script with filename being just a question mark to get a working command as ?, that shows all commands in fzf menu if no argument is given or shows the cheatsheet in the less pager if command name is given.

Usage:

?
? -l
? date
? grep

Script ?:

#!/bin/env bash

cheat='curl -s cheat.sh'
menu='fzf --reverse'
pager='less -R -c'
cachefile_max_age_hours=6

# Path to temporary cache file. If your Linux system does not support /dev/shm
# or if you are on MacOS, then change the path to your liking:
cachefile='/dev/shm/cheatlist'      # GNU+LINUX
# cachefile="${TMPDIR}/cheatlist"   # MacOS/Darwin

# Download list file and cache it.
listing () {
    if [ -f "${cachefile}" ]
    then
        local filedate=$(stat -c %Y -- "${cachefile}")
        local now=$(date +%s)
        local age_hours=$(( (now - filedate) / 60 / 60 ))
        if [[ "${age_hours}" > "${cachefile_max_age_hours}" ]]
        then
            ${cheat}/:list > "${cachefile}"
        fi
    else
        ${cheat}/:list > "${cachefile}"
    fi
    cat -- "${cachefile}"
}

case "${1}" in
    '')
        if selection=$(listing | ${menu})
        then
            ${cheat}/"${selection}" | ${pager}
        fi
        ;;
    '-h')
        ${cheat}/:help | ${pager}
        ;;
    '-l')
        listing
        ;;
    *)
        ${cheat}/${@} | ${pager}
        ;;
esac
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 1 month ago (1 children)

This looks great.

Suggestion: a step-by-step "howto" with an example or three to make it more useful for beginners.

[–] [email protected] 1 points 1 month ago

Thanks. Is this suggestion towards this ? script or the output from the cheat.sh web service? Because I'm not the author of the web service itself, I just created this script to make use of it.