Hacker News new | ask | show | jobs
by campground 1184 days ago
Here's a little function that I use pretty often when I want to install a package but I'm not sure what the exact package name is. Give it a keyword and it searches apt-cache and dumps the results into fzf.

  function finstall {
      PACKAGE_NAME=$(apt-cache search $1 | fzf | cut --delimiter=" " --fields=1)
      if [ "$PACKAGE_NAME" ]; then
          echo "Installing $PACKAGE_NAME"
          sudo apt install $PACKAGE_NAME
      fi
  }
1 comments

I have a similar one for Homebrew, with the ability to preview package info and install multiple targets:

    # ~/.config/fish/functions/fbi.fish
    function fbi -a query -d 'Install Brew package via FZF'
        set -f PREVIEW 'HOMEBREW_COLOR=1 brew info {}'
        set -f PKGS (brew formulae) (brew casks |sed 's|^|homebrew/cask/|')
    
        set -f INSTALL_PKGS (echo $PKGS \
            |sed 's/ /\n/g' \
            |fzf --multi --preview=$PREVIEW --query=$query --nth=-1 --with-nth=-2.. --delimiter=/)
    
        if test ! -z "$INSTALL_PKGS"
            brew install $INSTALL_PKGS
        else
            echo "Nothing to install…"
        end
    end