• [object Object]@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    2
    ·
    3 months ago

    I have a script named d in my PATH and it contains this:

    ("$@" > /dev/null 2>&1 &)
    

    It allows me to run any program in a fully detached state in a way that works even if the terminal that started the program closes, and it’s as simple as d <command>.

      • [object Object]@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        3 months ago

        () creates a subshell, and & runs the command in background. The $@ means everything after the first argument, so the <command> is executed like a normal command. I am not sure why this works, but it has worked more consistently than nohup, disown, and it’s a lot shorter than most other solutions.

      • [object Object]@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        3 months ago

        IIRC disown is a shell built-in command, so its use is a bit limited. Not sure if & is also a built-in, but I found disown to not work in some situations. Besides, it’s shorter.

        • stewie410@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          3 months ago

          shell built-in command

          After looking into it a bit more, its at least a builtin for bash but is otherwise not POSIX. I guess nohup ... & would be the POSIX compliant equivalent, though still not a builtin.

          Its my understanding that & backgrounds, not necessarily detaches, a process – if the parent process closes, I think the background tasks would still be wait()ed on, if only using &.

    • Victor@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      What do y’all use awk for really? 20 of using Linux, I’ve never had to use awk. And I’ve done a looot of scripting in my days. Anything from building my own clone of polybar using eww (with loads of scripts underneath), to automated systems for bulk handling of student assignments back at uni when I used to help out with grading and such.

      What’s awk good for that other standard utilities can’t do?

      • Onno (VK6FLAB)@lemmy.radio
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

        I’ve been using Linux for 25 years, awk is a more recent addition to my arsenal, but rapidly becoming more and more useful.

        For example, awk is extremely helpful if you want to rearrange columns, do math on columns, essentially do things that would take multiple lines of bash with cut and read.

  • hallettj@leminal.space
    link
    fedilink
    English
    arrow-up
    0
    ·
    3 months ago

    When I’m in some subdirectory of a git repository, I use this command to jump to the repo root:

    alias gtop="cd \$(git rev-parse --show-toplevel)"
    
    • Victor@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      What I do with all git related aliases is I alias git to just g in the shell. Then for any alias I want that uses git I just put that alias in the global git config under the alias section.

      This avoids polluting the shell with a bunch of git-specific aliases. Just the one, g.

      • hallettj@leminal.space
        link
        fedilink
        English
        arrow-up
        0
        ·
        3 months ago

        I certainly see the value in this strategy! But I’m not going to give up my top-level aliases. I enjoy saving two keystrokes too much!

        Here are my most used aliases (these ones use Nushell syntax):

        alias st = git status
        alias sw = git switch
        alias ci = git commit
        alias lg = git log --color --graph '--pretty=format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
        alias push = git push
        

        I was also delighted to learn that I could get the same short aliases for corresponding fugitive commands in vim/neovim using the vim-alias plugin:

        -- This is a lazy.nvim plugin module
        return {
          'Konfekt/vim-alias',
          config = function()
            -- Shortcuts for git operations to match some of the shell aliases I have.
            -- For example, `:sw ` expands to `:Git switch `
            vim.cmd [[Alias sw Git\ switch]]
            vim.cmd [[Alias ci Git\ commit]]
            vim.cmd [[Alias pull Git\ pull]]
            vim.cmd [[Alias push Git\ push]]
            vim.cmd [[Alias show Git\ show]]
            vim.cmd [[Alias re Git\ restore]]
            vim.cmd [[Alias lg GV]]
          end,
        }
        

        Fugitive is very nice for integrating git workflows in the editor, and its commands have very nice tab completion for branches and such.

        • Victor@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          3 months ago

          two keystrokes

          For me I’d be saving one keystroke. Status for me would be g s, g c for commit, and so on. Single letter aliases for the most common commands, two letters for less common in a conflict. 😁

          But these days since a few years back I just use lazygit (aliased to lg btw, lol).

          Everything in lazygit is basically just single keystrokes also. c for commit, etc. Very handy.

          Fugitive

          Cool beans, sounds like a good tool! I’m on team Helix since a few years, after being a vim/nvim user for about a decade, and emacs a couple years before that. Helix’s paradigm just makes so much sense. 🎯👌 Jumping around symbols intra-file and inter-file, and LSP support built-in, no fussing. Worth a try for a few weeks if you ask me.