A fish shell script to easily deal with Arch Linux's pacman

A fish shell script to easily deal with Arch Linux's pacman

I made a simple script in fish shell that runs pacman commands without those hard-to-remember arguments and flags. In fact it resembles FreeBSD's pkg commands.

pkg is a function which is an alias for the Arch based Linux distributions. The name “pkg” is inspired by the FreeBSD package manager pkg. Which means pkg-fish has some similarities with the pkg itself.

Installation

  1. Install fish shell on your device.
  2. Copy or place the pkg.fish file into the fish’s conf.d folder located in $HOME/.config/fish.
  3. Source the file soure ~/.config/fish/config.fish or open a new terminal.
  4. Type pkg followed by a space and autocompletion will start to work.

Usage

pkg is similar to FreeBSD’s pkg command with additional shortcuts and arguments.

Additional arguments > -y alias for --noconfirm in pacman -s alias for -yy in pacman (force sync)

argumentshortcutpacman commandadditional argumentdescription
installi, inpacman -S-y, -sInstall packages
remover, rmpacman -Runsc-yRemove packages
updateu, uppacman -Su-y, -sUpdate packages
findf, fdpacman -Si-sQuery a package
searchspacman -Ss-sSearch packages

Example

Assuming you have added the pkg.fish file into the conf.d folder which makes the pkg function executable.

Search a package

pkg search vifm

# pacman command
pacman -Ss vifm

Install a package with assuming yes to all the propmts

pkg i vifm -y

# pacman command
sudo pacman -S --needed --noconfirm vifm

Updating the system with force sync

pkg up -s

# pacman command
sudo pacman -Su --needed -yy

You don’t have to enter sudo

Certain pacman commands requires sudo command to run such as installing or removing packages. pkg already has added sudo into those commands, eliminating the need of typing sudo with pkg.

If you don’t want to use fish as your default shell

In that case you can create an alias in you defalut shell (bash, zsh) alias pkg='fish -c "pkg $@"'


Happy fishing

More from linux