• tyler@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    You can use - everywhere you can use a ref in a git command. I very often use

    git checkout master
    git pull
    git checkout -
    git merge -
    

    (Of course that’s all aliased and I have other flags in there too, but that’s the gist)

    • NostraDavid@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Same for cd -. Nice if you want to go to /etc/blah, and then back to where you were.

      You can also use pushd and popd which will push and pop directories from a stack, if you need to do something more complex.

      Also, if you want to switch faster between branches, slap this in your ~/.gitconfig under [alias]:

      co = !git checkout $(git for-each-ref refs/heads/ --format='%(refname:short)' | fzf)

      Presuming you’ve got fzf installed, you can now git co (co = checkout) to get a menu with fuzzy find capabilities to switch between branches. Nice if branch names are long/similar/only-different-at-the-end.

      fzf is dope.

  • ShaunaTheDead@fedia.io
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    My favorite tips are:

    You can filter the output of a command. Most commands return parameters like (output, error) so you can filter them by number like 1>/dev/null will filter the output and only show the errors, and 2>/dev/null will filter the errors and only show the output. Also if you want a command to run silently but it doesn’t have it’s own built-in quiet mode you can add &>/dev/null which will filter everything.

    Bash (and other shell’s I assume) can be fully customized. In addition to the .bashrc file in your home directory, there are also a few common files that bash will look for like .bash_aliases, .bash_commands, .bash_profile or you can create your own and just add to the end of the .bashrc file ./YOUR_CUSTOM_BASH_FILE_NAME

    Inside that file you can add any custom commands you want to run for every bash shell like aliases and what not.

    I personally often use a simple update command like so alias up='sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y' which just makes running updates, upgrades, and clean-up so much easier. Just type up and enter your password. I have previously added in things like &>/dev/null to quiet the commands and echo Fetching updates... to make some commands quieter but still give some simple feedback.

    There’s also the basics of moving around a terminal command as others have pointed out. The easiest and the one I use the most is if you hold CTRL+LEFT_ARROW the cursor will move entire words instead of one character at a time. Very helpful if you need to change something in the middle of a command.

  • some_guy@lemmy.sdf.org
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    Ctl-U to delete everything on the line before cursor.

    Ctl-E to skip to end of line.

    Ctl-A to skip to beginning of line.

      • NostraDavid@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        4 months ago

        Kids these days….

        These Ctrl keys are shortcuts from Emacs - there’s a Bash settings to switch to vi-mode if you so wish. Anyway, the first Emacs was written in 1981, probably on a PDP-11, which did not have Home and End! Same reason Neovim uses “yank” instead of “copy”. ctrl-c/ctrl-v did not exist as a shortcut back when vi was being written!

        I know you didn’t intend to be mean or anything, but maaaaaan kids these days don’t know their history (not entirely your fault, btw)😆

      • Ferk@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        4 months ago

        That’s horrible for muscle memory, every time I switch desk/keyboard I have to re-learn the position of the home/end/delete/PgUp/PgDn keys.

        I got used to Ctrl-a / Ctrl-e and it became second nature, my hands don’t have to fish for extra keys, to the point that it becomes annoying when a program does not support that. Some map Ctrl-a to “Select all” so, for input fields where the selection is one line, I’d rather Ctrl-a then left/right to go to the beginning/end than fish for home/end, wherever they are.

      • ShaunaTheDead@fedia.io
        link
        fedilink
        arrow-up
        0
        ·
        4 months ago

        This tip is super useful to me because not everyone is using a PC. On a PC sure, I would use the Home and End keys all the time. Now I’m using a laptop as my main computer and the Home and End keys are in a weird position that even to this day, 4ish years of laptop use, I still have to actually look at the keys to find them.

    • Hammerheart@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      4 months ago

      ctrl-b: move cursor back one character

      ctrl-f: move cursor foward one character

      ctrl-d: delete character under cursor