• cally [he/they]@pawb.social
    link
    fedilink
    arrow-up
    14
    ·
    12 hours ago

    I usually use --help as it also gives descriptions for the command, though some programs may only accept -h or no argument to show the help menu.

  • u/lukmly013 💾 (lemmy.sdf.org)@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    5
    ·
    12 hours ago

    I’d like something like on Cisco equipment.

    Tab completes a command
    ? prints possible options with brief descriptions, filtered by starting letters if you already typed anything
    if there is just one option left, you can just use it directly, so you can write shortened commands (similar to ip commands on Linux)

    • antimidas@sopuli.xyz
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      12 hours ago

      That would be the dream indeed. It’s so fluid after you learn it. Other networking equipment often has good configuration CLIs as well (like juniper and vyos), but Cisco is probably the best in my experience. It’s also nice how consistent they are across generations.

      You can get about as close as it’s possible in a normal operating system with zsh and plugins like zsh-autocomplete. Bash tries to pick up the possible alternatives from context as well (with tab suggestions) that act somewhat like ? on Cisco CLI, but implementing it is left up to the command itself to provide for the shell. Many commands luckily provide very robust autocompletion to bash out-of-the-box, especially if installed via the system package manager.

      Unfortunately we’ll probably never reach the point of actual configuration CLIs since they only have a set amount of commands that are developed by the same company. It would be close to impossible to achieve the same level of standardisation for a general operating system, as we don’t know the entire configuration of the system and there are multiple incompatible flag schemes. (As styles go, things like dd and ffmpeg throw a wrench in the works with their non-standard flags)

  • trxxruraxvr@lemmy.world
    link
    fedilink
    arrow-up
    51
    arrow-down
    1
    ·
    19 hours ago

    Anyone who is learning new stuff in this thread should really try fish, it makes using the command line so much nicer.

  • FishFace@piefed.social
    link
    fedilink
    English
    arrow-up
    104
    ·
    21 hours ago

    These auto-completions are dependent on having the corresponding completions information installed and enabled. Which it is with most modern distros, but more bare-bones setups won’t have it.

      • ulterno@programming.dev
        link
        fedilink
        English
        arrow-up
        10
        arrow-down
        1
        ·
        edit-2
        17 hours ago

        In case of Arch, for bash, you have the bash-completions package, apart from which some program packages install their own bash completions.
        Then there is also zsh-completions for zsh.

        I remember having to install them separately, but maybe you know some package group that did it for you.

  • thevoidzero@lemmy.world
    link
    fedilink
    arrow-up
    14
    ·
    15 hours ago

    Whenever someone says they don’t really like terminal because they don’t like to type or remember commands. This is what I think “they didn’t use auto complete”.

    Auto complete works for file names and paths by default, but the development can write it to only complete certain extensions. Like auto complete for image program only completes image files. Then you have completion for commands, subcommands and flags.

    Auto complete is done through calling a bash script with currently typed line, and the bash script can call other commands. So developer can write a really complicated auto complete and make it available as a binary if they want, and just use that in bash. Or you can use many tools that will generate auto complete script for you based on your commandline args.

    If you write your own scripts/cli binaries I recommend learning how to write auto complete for it. Makes it incredibly easy to use the tools.

    • alias_qr_rainmaker@lemmy.worldOP
      link
      fedilink
      arrow-up
      7
      arrow-down
      2
      ·
      15 hours ago

      i was in the dark for so long because i thought tab autocompletions only worked with file paths. i can’t believe that whole time i didn’t even accidentally hit tab once on a command

      • thevoidzero@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        15 hours ago

        I guess it can go unnoticed, I use Arch so maybe that’s why I got more involved. I remember searching why auto completion didn’t work, then finding out I need to install bash-completions package. After knowing that it makes one curious about how it works. Then the next stage is writing it for my own programs because it obviously won’t come with bash-completions package.

        I once wrote a shell (terminal) to watch anime, and I wrote auto completion for different commands on it, it was really nice to just type play then prefix and then tab for auto completion on anime names, and even for episodes I wrote auto completion give me last episode I watched + 1.

      • Multiplexer@discuss.tchncs.de
        link
        fedilink
        arrow-up
        53
        ·
        edit-2
        18 hours ago

        Lets you easily and interactively search your command history.
        Half the stuff I do is usually preceded by that, it’s really useful!

        • Jack@slrpnk.net
          link
          fedilink
          arrow-up
          96
          ·
          22 hours ago

          Oh that is nice, I usually use ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

          • groet@feddit.org
            link
            fedilink
            arrow-up
            8
            arrow-down
            1
            ·
            20 hours ago

            Yeah standard bash Ctrl+r is just so painful. I much rather use “history | grep searchtearm” than that awfull search. fzf is a whole other level. But nowadays I just use fish shell which IMO has even better search than fzf

        • ulterno@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          arrow-down
          1
          ·
          16 hours ago

          I have been suggested alternative programs to install to work with Ctrl+r, which are supposed to work better, but I just end up using kwrite ~/.bash_history when Ctrl+r fails.

    • neidu3@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      7
      ·
      23 hours ago

      I accidentally stumbled across Ctrl+r over a decade ago and I still don’t understand properly how it works. So I usually egrep -e someInsaneRegex ~/.bash_history

      • ∃∀λ@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        14 hours ago

        The part of the tech stack that handles all these command editing and navigation shortcuts is the readline library. Check out man readline. There’s an entire section on searching. readline is used for lots of other interpreters, too.

      • FishFace@piefed.social
        link
        fedilink
        English
        arrow-up
        2
        ·
        21 hours ago

        That is worth it for more complicated things like, “I want all commands that started with git and contained ‘foo’”

        • Prunebutt@slrpnk.net
          link
          fedilink
          arrow-up
          7
          ·
          edit-2
          22 hours ago

          If you install a fuzzyfinder, like fzf, or skim, you get previews of the search query result and fuzzy search, which is really cool, too.

        • crater2150@feddit.org
          link
          fedilink
          arrow-up
          3
          ·
          9 hours ago

          I used fzf before atuin, and it works pretty similar, but atuin has a few additional features, as it tracks more information than the normal shell history. For example, you can also search only for commands that you executed in the current directory (great for stuff that is project specific). Or, if you use the history syncing feature, you can toggle search for commands you executed on either any or only the current machine.

    • alias_qr_rainmaker@lemmy.worldOP
      link
      fedilink
      arrow-up
      6
      arrow-down
      3
      ·
      edit-2
      23 hours ago

      dude holy shit that is AWESOME! i had something similar, but it was a custom function.

      srch() { cat ~/.bash_history | grep -Ein “$@”}

      • Korthrun@lemmy.sdf.org
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        14 hours ago

        Did you know that grep can take the name of the file(s) you want it to search as the final arguments?

        For example: grep -Ein "$@" ~/.bash_history

  • lazynooblet@lazysoci.al
    link
    fedilink
    English
    arrow-up
    27
    ·
    22 hours ago

    Does it depend on some shell or shell extension? My bare bones Debian installs don’t do this. Powershell does but I’d like it on Linux too.

    • smeg@feddit.uk
      link
      fedilink
      English
      arrow-up
      14
      ·
      21 hours ago

      You can install powershell on Linux if you’re feeling masochistic

            • AMoistGrandpa@lemmy.ca
              link
              fedilink
              arrow-up
              3
              ·
              edit-2
              18 hours ago

              If you feel like learning a third shell, I find that Nushell is even easier to use than PowerShell.

              open stuff.json | each { get fieldName } | where { str starts-with "asdf" } | each { $in | str upcase }

              This gets all the objects in the given json file, then grabs the value of the field named “fieldName”, then filters all those values to find the ones that start with and, converts those to uppercase, and prints them to the screen as a nicely formatted list

              • AeonFelis@lemmy.world
                link
                fedilink
                arrow-up
                1
                ·
                15 hours ago

                You don’t need the $in | in that last command. each { str upcase } will already pipe each item to the str upcase command.

            • ulterno@programming.dev
              link
              fedilink
              English
              arrow-up
              1
              arrow-down
              1
              ·
              16 hours ago

              Yeah, it does tend to be hard to determine when to use () {} [] etc.
              Even after I RTFM and used those in scripts multiple times, I tend to forget it by the time I need to implement something next.

      • rtxn@lemmy.worldM
        link
        fedilink
        arrow-up
        6
        ·
        21 hours ago

        ZSH still needs the completion data files to be installed. It won’t just magically know the completions.

        • floquant@lemmy.dbzer0.com
          link
          fedilink
          arrow-up
          4
          ·
          19 hours ago

          Ah you’re right, my bad. I automatically install oh-my-zsh so I forget how much functionality is bundled into it. Edited

    • The Quuuuuill@slrpnk.net
      link
      fedilink
      English
      arrow-up
      1
      ·
      17 hours ago

      yeah you’ll have to install some helper scripts or switch to either fish or zsh. bash is nicer than bourne shell, but it is VERY basic in features by modern standards

    • Dave@lemmy.nz
      link
      fedilink
      arrow-up
      2
      ·
      22 hours ago

      I don’t know the answer but does tab to autocomplete work in other contexts? E.g. you type ‘cd ca’ and it fills it to ‘cd catpics’?

      I’m not at a PC right now but from memory you’d have to be in bash or similar, it won’t work in sh.

  • pedz@lemmy.ca
    link
    fedilink
    arrow-up
    7
    ·
    17 hours ago

    For a moment I thought that ‘commandName -’ was some PowerShell stuff.

      • pedz@lemmy.ca
        link
        fedilink
        arrow-up
        3
        ·
        16 hours ago

        It can’t hurt to know this but to me PS is not intuitive, looks like SomeLongString-ActingLikeA-Command, and I avoid it as much as using Windows in the first place, unless absolutely necessary.

    • trxxruraxvr@lemmy.world
      link
      fedilink
      arrow-up
      15
      ·
      22 hours ago

      It depends on the shell you’re using, if it’s enabled and if you have completions for that particular command installed. For bash you might have to install a bash-completion package, depending on your Linux distro. Zsh is similar but had more powerful and user friendly completion options. Fish is even better and comes with completion for a lot of standard commands pre-installed.

    • alias_qr_rainmaker@lemmy.worldOP
      link
      fedilink
      arrow-up
      4
      arrow-down
      3
      ·
      22 hours ago

      2018? i was 2017. that was the year i went to a coding bootcamp, so they had us all on macs. I know y’all despise mac users with a passion, but we learned how to use the bash terminal. I didn’t know cd was a bash exclusive thing until recently. Most of the time I use zsh, and I’d always type cd when actually you can just type the path of the directory and hit enter

      • trxxruraxvr@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        edit-2
        22 hours ago

        cd is not bash exclusive, it’s the standard POSIX way to change directories. Zsh is the outlier here, being more use friendly than most shells.

        • alias_qr_rainmaker@lemmy.worldOP
          link
          fedilink
          arrow-up
          4
          arrow-down
          2
          ·
          20 hours ago

          i got used to bash back in 2017 when i went to a bootcamp. but i’m a mac user so i mostly do zsh. you’re not gonna believe how long i went until i discovered that you can cd into a directory just by typing the directory

          it was a week ago

      • fartsparkles@lemmy.world
        link
        fedilink
        arrow-up
        6
        ·
        22 hours ago

        I’d rather a Mac than a Windows box. At least you get a proper shell (zsh or bash - zsh is the default now I think), python installed by default, can install package managers (macports, brew), can get coreutils, etc and most FOSS software from the Linux world runs since macs are UNIX at heart.

        I’m pretty sure cd isn’t even coreutils but implemented by shells as a wrapper for chdir/fchdir which is part of the kernel. Which has always bugged me since you can’t reliably pipe or redirect to cd since shells do things differently; it doesn’t handle stdin or the last component of a command runs in a subshell so doesn’t affect your current shell, blah blah.

        • alias_qr_rainmaker@lemmy.worldOP
          link
          fedilink
          arrow-up
          1
          arrow-down
          2
          ·
          13 hours ago

          i fucking love wrappers, i wanna be the best wrapper alive. my schizo theory is that we’re in a simulation and the entire english language is just wrappers for insanely nested ruby function calls

      • ReginaPhalange@lemmy.world
        link
        fedilink
        arrow-up
        6
        ·
        16 hours ago

        A TLDR alternative to man pages
        While a man page is for every possible flag available for a command,
        A tldr is for the most common tasks a command can do.

        tldr fc
        
        fc
        
          Open the most recent command for editing and then run it.
          More information: https://www.gnu.org/software/bash/manual/bash.html#index-fc.
        
          - Open the last command in the default system editor and run it after editing:
            fc
        
          - Specify an editor to open with:
            fc -e 'emacs'
        
          - List recent commands from history:
            fc -l
        
          - List recent commands in reverse order:
            fc -l -r
        
          - Edit and run a command from history:
            fc number
        
          - Edit commands in a given interval and run them:
            fc '416' '420'
        
          - Display help:
            fc --help