MyNixOS website logo
Description

CLI program for profiles management.

Please see the README on GitHub at https://github.com/illia-shkroba/pfile#readme

PFile

PFile is a CLI program that manages different sets of filesystem's objects (directories, directory links, files, file links) called "profiles".

With PFile you could define multiple profiles (especially for the same sets of files) and switch between them.

Usage

Let's say you want to manage multiple versions of your Shell's history and Browser's history/cookies. One version is for your private use and the second is for your work.

With PFile you could use the new command to create a new profile:

pfile new private -- ~/.cache/zsh/ ~/.config/BraveSoftware/

This command would move the ~/.cache/zsh/ and ~/.config/BraveSoftware/ into the new profile called "private". After running the new command, the ~/.cache/zsh/ and ~/.config/BraveSoftware/ are gone from their original locations. But no worries, they are still available inside of the ~/.local/share/pfile/profiles/private/absolute/ directory.

After creating the "private" profile, you could use the switch command to switch to it:

pfile switch private

This would create the following links in place of the original directories:

readlink -e -- ~/.cache/zsh/ ~/.config/BraveSoftware/
# /home/is/.local/share/pfile/profiles/private/absolute/home/is/.cache/zsh
# /home/is/.local/share/pfile/profiles/private/absolute/home/is/.config/BraveSoftware

The ~/.cache/zsh/ and ~/.config/BraveSoftware/ have become links pointing at "private" profile's entries:

ls "$(readlink -e -- ~/.cache/zsh/)"
# history
ls "$(readlink -e -- ~/.config/BraveSoftware/)"
# Brave-Browser

Now let's try to create an another profile called "work" for the same files:

pfile new work -- ~/.cache/zsh/ ~/.config/BraveSoftware/

This command would copy the contents of ~/.cache/zsh/ and ~/.config/BraveSoftware/ into the new profile called "work". The "private" profile will remain untouched. The new command performed copy this time instead of move, because it has detected that the provided filesystem's objects are symbolic links.

You could check which profile is currently set with the which command:

pfile which
# private

You can see that the new command did not perform a switch. If you want to switch to the "work" profile, you could use the switch command:

pfile switch work
pfile which
# work

If you don't want to copy the contents of ~/.cache/zsh/ and ~/.config/BraveSoftware/ into a new profile, you could pass the -e (or --empty) option to the new command. This option would cause new command to create empty directories for ~/.cache/zsh/ and ~/.config/BraveSoftware/ inside of the new profile. Note that the --empty option only affects links. Other directories and files you provide would be moved to the new profile.

pfile new -e work2 -- ~/.cache/zsh/ ~/.config/BraveSoftware/
pfile switch work2

You could try now to reopen your Shell/Browser. You will notice that there is no history.

If you want to bring the directories back to their original locations, you could use the unpack command:

pfile unpack
pfile which
# No current profile set. Use `pfile new` to create a profile and `pfile switch` to switch to it.

After using the unpack command, the directories are brought back to their original locations, but their copies are still kept inside of the profile:

readlink -e -- ~/.cache/zsh/ ~/.config/BraveSoftware/
# /home/is/.cache/zsh
# /home/is/.config/BraveSoftware

readlink -e -- /home/is/.local/share/pfile/profiles/work2/absolute/home/is/.cache/zsh
# /home/is/.local/share/pfile/profiles/work2/absolute/home/is/.cache/zsh
readlink -e -- /home/is/.local/share/pfile/profiles/work2/absolute/home/is/.config/BraveSoftware
# /home/is/.local/share/pfile/profiles/work2/absolute/home/is/.config/BraveSoftware

If you would try to switch back to the "private" profile, you would get this error:

pfile switch private
# Unable to link origin "/home/is/.cache/zsh" to entry "/home/is/.local/share/pfile/profiles/private/absolute/home/is/.cache/zsh" because the origin is occupied.

This happens because ~/.cache/zsh/ has become a directory instead of a directory link pointing at the profile's entry. Thus, PFile refuses to overwrite it. You could remove (or move) the directory manually or if you want to forcibly remove it with PFile, you could use -f (or --force-remove-occupied) option of the switch command:

pfile switch -f private

This would forcibly remove both:

  • Filesystem's objects where the current profile's links are expected to be placed (only if the current profile is set).
  • Filesystem's objects where the next profile's (the one you provide to the switch command) links are expected to be placed.

Motivation

I work as an academic teacher and often use my terminal during lectures. When using keybindings like CTRL-R in my Shell to search for a recent command from my history, sometimes my private commands could pop-up like pass insert <some-service>@<my-account> or KEY=<my-private-key> ansible... or mpv 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'. The same goes for my Browser's history.

At first, I wanted to solve this issue by creating a separate user on my system specifically for lecture purposes. But then I've realized that:

  1. All of my personal configs that I wish to use during lectures like Neovim, Xmonad and Qutebrowser configs should be copied to the new user's home directory.
  2. When I change one of the configs on my main user, I should rsync the new configs to the other user.
  3. Permissions of resources (e.g.: directories and files) that I use on both users should be handled.

The PFile program solves the issue for me.

Metadata

Version

0.1.0.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows