• Dave@lemmy.nz
        link
        fedilink
        arrow-up
        4
        ·
        14 hours ago

        Just checking, because I learnt to type before I worked this out, and because surely someone reading doesn’t know: press tab. Bash will fill in file names from your current directory.

        E.g. say you have files fred1file, fred2file, jim.

        Type f then press tab, it will fill to “fred”. Then press 2 and press tab again and it will fill the full “fred2file”.

        Have a play, it works in heaps of situations.

        • bobo@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          2 hours ago

          Bash will also do autocomplete for cli programs that have autocomplete functionality. Try typing:

          git r<tab><tab>

          you’ll see options for all the git commands that start with r. Often cli commands will have autocompletion for long (double dash) options.

          If you want to see all the commands that have auto complete available, look in:

          /usr/share/bash-completion/completions/

          There’s a few other locations they can live, notably:

          /etc/bash_completion.d/ ~/.bash_completion ~/.local/share/bash-completion/completions/

          I don’t know if there are more or if there is any variation per distro.

          You can also write your own bash completions. They can get pretty smart and context sensitive.

          Pretty good beginning tutorial:

          https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial

          edit - I should’ve mentioned that this isn’t native to bash, it requires installation of bash-completion. But bash-completion is installed by default in many distros.

      • ch00f@lemmy.world
        link
        fedilink
        arrow-up
        33
        ·
        22 hours ago

        Shit is usually a pain in the ass. The challenge is divining how much of a pain in the ass something has to be that someone else might have made a solution for it.

        I didn’t know you could ctrl+shift+c to copy in the terminal until a month ago when my linux n00b wife said "there has to be a better way to do this. I’ve been right clicking to copy for 10 years.

      • grrgyle@slrpnk.net
        link
        fedilink
        arrow-up
        7
        ·
        18 hours ago

        Congratulations! I remember where I was when I first learned it (in a noisy server room at the back of a machine shop).

        Now pair it with FZF for fuzzy finding – it’s surprisingly easy to set up, just following any guide. It’s insanely useful. I find myself even doing things like typing:

        $ xinput --disable $(xinput --list | grep -i touchpad | grep 'id=[0-9]\+' -o | cut -d= -f2)  # Disable synaptic touchpad trackpad pointer
        

        commands with these like comments on the ends as sort of “tags” so I can ctrl+r search for them later. Yes, I know I could just use a named function, but this is like the step just before that–before I know if I’ll be issuing the same command all the time, or just for the next couple weeks. (This one was from when I was resting my notebook on my laptop.)

        • oddlyqueer@lemmy.ml
          link
          fedilink
          English
          arrow-up
          3
          ·
          15 hours ago

          I like this; I have a lot of commands that I don’t use often enough to justify an alias, but still need to rerun all the time. thanks!

      • lmmarsano@lemmynsfw.com
        link
        fedilink
        English
        arrow-up
        5
        ·
        edit-2
        19 hours ago

        As usual, that’s documented (we can RTFM).

        Before trying ctrl-s, you may want to disable software flow control: run stty -ixon & add it to your initialization files. Otherwise, you’ll pause terminal output. ctrl-q resumes terminal output.

        stty reveals terminal special characters

        $ stty -a
        ⁝
        intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; …
        ⁝
        

        These special characters/keys often perform special functions. To illustrate

        • ctrl-d on empty input typically exits/logs out of interactive terminal applications (including shells)
        • ctrl-u discards input (useful for inputs like password prompts that don’t echo input back)
        • ctrl-v inputs next character literally (such as tab)
    • Cenzorrll@lemmy.world
      link
      fedilink
      arrow-up
      11
      ·
      edit-2
      22 hours ago

      I’m not going to say how long I used linux before learning this. It isn’t “this many days old”, but it may as well be.

      I have 7 headless linux boxes running.

    • Damage@feddit.it
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      21 hours ago

      Even quicker with zsh or atuin: write the first few letters then arrow up to cycle through all matches

      • Ephera@lemmy.ml
        link
        fedilink
        English
        arrow-up
        6
        ·
        20 hours ago

        Even quicker with fish: Write the first few letters then it auto-suggests the last-run command matching that prefix (and then you can still arrow up to cycle through all matches).

        (There is also a zsh plugin for that, called zsh-autosuggestions.)

        • Cethin@lemmy.zip
          link
          fedilink
          English
          arrow-up
          2
          ·
          17 hours ago

          A lot of stuff assumes Bash, so occasionally when the syntax differs its slightly annoying; sometimes you have to modify a few lines of a file or something (or run it as in Bash manually). Fish is so nice though. It really should replace Bash for almost everyone. If you really need Bash you can still use it.

          • Ephera@lemmy.ml
            link
            fedilink
            English
            arrow-up
            5
            ·
            14 hours ago

            With script files, you can (and should regardless of Fish usage) put a shebang at the top, like #!/bin/sh or #!/bin/bash. Then it will run with Bash as you’d expect.

            I also recommend not setting Fish as your system-wide default shell (since then a missing shebang will cause it to run in Fish), but rather just have your terminal emulator start fish by default.

            And yeah, outside of scripting, if I notice a command requires Bash syntax (which you can often tell from Fish’s syntax highlighting turning red), then I just run bash, execute the Bash command in there and then exit back out of there.

            Having said all that, I’m not trying to take away from your point. If I wasn’t just joking around, I would caveat a Fish recommendation just as much.

            • Cethin@lemmy.zip
              link
              fedilink
              English
              arrow-up
              2
              ·
              12 hours ago

              Yeah, it’s just some scripts that come with programs sometimes not including that is the issue. Like I said, it isn’t a big issue, just occasionally requires small edits if you try to run the script in Fish, or, like you said, running them with Bash.

    • Mikelius@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      15 hours ago

      I’m shocked how far I had to scroll down before it was mentioned, I was getting scared I would have to say it lol

    • Jankatarch@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      22 hours ago

      I like to imagine someone added it in for their own personal use and told nobody because surely they are the only one.