pfile: CLI program for profiles management.

[ bsd3, filesystem, library, program ] [ Propose Tags ] [ Report a vulnerability ]
Versions [RSS] 0.1.0.0, 0.1.0.1
Dependencies aeson (>=2.1.2 && <=2.2.3.0), aeson-pretty (>=0.8.9 && <0.9), base (>=4.7 && <5), directory (>=1.3.7 && <1.4), filepath (>=1.4.2 && <1.5), HUnit (>=1.6.2 && <1.7), mtl (>=2.2.2 && <=2.3.1), optparse-applicative (>=0.17.1 && <=0.18.1.0), pfile, protolude (>=0.3.3 && <0.4), temporary (>=1.3 && <1.4), transformers (>=0.5.6 && <=0.6.1.0), unordered-containers (>=0.2.19 && <0.3) [details]
License BSD-3-Clause
Copyright 2024 Illia Shkroba
Author Illia Shkroba
Maintainer is@pjwstk.edu.pl
Category Filesystem
Home page https://github.com/illia-shkroba/pfile#readme
Bug tracker https://github.com/illia-shkroba/pfile/issues
Source repo head: git clone https://github.com/illia-shkroba/pfile
Uploaded by is at 2024-07-26T11:20:00Z
Distributions LTSHaskell:0.1.0.1, NixOS:0.1.0.1
Executables pfile
Downloads 79 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for pfile-0.1.0.1

[back to package description]

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.