Package: pearl
PearlProject StatusDonationCommunicationTable of ContentsDescriptionQuickstartInstallationDependenciesLinuxOSXCreate your own Pearl packageCreate your own Pearl repositoryComparison with alternative solutionsTroubleshootingContributingDonatingAuthorsDescriptionPearlis a lightweight package manager for automating reproducible environments
between different systems (Linux and OSX).
It can be used for dotfiles, plugins, programs and any form of code
accessible via git.As soon as a package gets installed, its content can be activated out of the box
according to certain events, like, for instance, a shell startup (Bash, Zsh or Fish) or
an editor startup (Vim or Emacs). This is possible via a smart and simplehook mechanismthat integrates the package content within the Pearl ecosystem.The main advantages on using Pearl are:Create your own Pearl package in a very simple way.Full control and sync of your dotfiles across different systems.Automatic bootstrap of the package content whenever shells or editors get started.Access to a wide range of existing packages via theOPH (Official Pearl Hub).Allows to create your own shareable package repository.Comparisonwith alternative solutionsStable codebase with 100+ unit tests and exhaustive integration tests viaTravisfor Linux and OSX.Small number ofdependenciesneeded in order to ensure compatibility with most of the systems.QuickstartThere are two main use cases for Pearl which will be explained here below:Use case 1: Create custom packageThe following example creates a Pearl package containing
agitdotfile and a simple executable available as soon
as the package gets installed.$>pearlcreatemydotfiles~/dotfilesThis will create a directorypearl-configin~/dotfilescontaining all the templates to help you
start writing a Pearl package.~/dotfilesdoes not need to be an empty directory.Additionally, the local repository in$XDG_CONFIG_HOME/pearl/pearl.conf(defaults to~/.config/pearl/pearl.conf)
will be updated with the new package entry calledmydotfiles.
This tells to Pearl where to look for the package:$>cat~/.config/pearl/pearl.conf
...
...
PEARL_PACKAGES["mydotfiles"]={"url":"~/dotfiles"}Place the git config inside~/dotfilesdirectory:$>cd~/dotfiles
$>echo-e"[alias]\n    cfg = config">gitconfig
$>echo-e"#!/bin/bash\necho Hello World!">hello
$>chmod+xhelloYou need now to give instructions about how to link thegitconfigfile into the system and make the executable available inPATH.
This is possible through thepearl-config/hooks.shfile. Just update it with the following:post_install(){linkgit"${PEARL_PKGDIR}/gitconfig"link_to_path"${PEARL_PKGDIR}/hello"return0}post_update(){post_install}pre_remove(){unlinkgit"${PEARL_PKGDIR}/gitconfig"unlink_from_path"${PEARL_PKGDIR}/hello"return0}This tells to Pearl tolinkthe git config located in"${PEARL_PKGDIR}/gitconfig"(${PEARL_PKGDIR}is a builtin variable)
to thegitprogram just after the package installation.
Also,hooks.shwill link the executablehelloby creating
a symlink and make it visible toPATHenv variable.
Conversely, before removal, the hooks file tells tounlinkthe git config file and remove the symlink.Now, just install the package and you will see the changes already reflected:$>pearlinstallmydotfiles
$>gitcfg-l
...
...
$>hello
HelloWorld!Once the package is completed, you can upload it to a git repository and
just fetch it from there by updating~/.config/pearl/pearl.conf:$>cat~/.config/pearl/pearl.conf
...
...
PEARL_PACKAGES["mydotfiles"]={"url":"https://github.com/pearluser/mydotfiles.git"}There are way more things you can do with Pearl!
For more details about thepearl-configcontent, look at thesectionbelow.Use case 2: Use Pearl Hub repositoryYou can just use existing packages from the Pearl Hub repository.
It contains a big list of packages about dotfiles, programs and plugins for many known applications.For instance, look to the entire list of packages:$>pearllistIf interested to search only for dotfiles:$>pearlsearchdotfiles
pearl/dot-gtkAwesomegtkdotfiles
pearl/kyrat20linesscriptthatbringsdotfilesinasshsession
pearl/dot-muttAwesomeMuttdotfiles
pearl/dot-emacsAwesomeemacsdotfiles
pearl/dot-gitAwesomegitdotfiles
pearl/dot-screenAwesomescreendotfiles
pearl/dot-tmuxAwesomeTmuxdotfiles
pearl/dot-vimAwesomevimdotfiles
pearl/dot-firefoxAwesomeFirefoxdotfiles
pearl/dot-termsAwesometermsdotfiles(i.e.urxvt)pearl/dot-bashAwesomebashdotfilesRecommended Pearl Hub packages to install:cmdkyratrangersesailatrash-clitxumInstallationDependenciesBefore installing Pearl be sure that all dependencies are properly installed in your system.
The Pearl dependencies are the following:Mandatorypython (>=3.7)bash (>=4.1)git (>=1.8.5)PLEASE NOTE: Tests may be performed on different versions from the ones listed above.
To know which versions are truly tested have a look at latest Travis executionshere.OptionalThe following are not mandatory dependencies but can be handy to have for the hook functions in Pearl package.
All the Linux distributions have these dependencies already installed.GNU coreutilsgrepsedShells supportedPearl supports the following shells:bash (>=4.1)fish (>=2.2.0)zsh (>=5.2)PLEASE NOTE: Tests may be performed on different versions from the ones listed above.
To know which versions are truly tested have a look at latest Travis executionshere.LinuxArch LinuxPearl can be installed in Arch Linux through AUR.
The package ispearl-git.For example, to install Pearl viayayAUR helper:$> yay -S pearl-gitAny other AUR helpers can be foundhere.Other Linux distributionsAssuming all Pearldependenciesare properly installed
in the system, to install Pearl you can use thepipcommand:$> sudo python3 -m pip install pearl
$> pearl initMake sure to updatePATHenvironment variable if needed
(pearlis typically located to/usr/bin).
The idempotentinitcommand will create the$PEARL_HOMEdirectory and
the new pearl configuration files from template.OSXIn order to install all Pearl dependencies, you first need to installHomebrew.To install all the needed dependencies via Homebrew:$>brewupdate
$>brewinstallbashgitcoreutilsgrepgnu-sedpythonTo install Pearl you can use thepipcommand:$>pip3installpearl
$>pearlinitMake sure to updatePATHenvironment variable if needed
(pearlis typically located to/usr/bin).
The idempotentinitcommand will create the$PEARL_HOMEdirectory and
the new pearl configuration files from template.IMPORTANT NOTE: Pearl gets loaded through~/.bashrc. The problem is that in OSX,
the terminal opens a login shell and only~/.bash_profilewill get executed.
Run the following only if~/.bashrcis not loaded within~/.bash_profilefile:$>echo"[[ -f$HOME/.bashrc ]] && source$HOME/.bashrc">>~/.bash_profileThis will make sure that~/.bashrcwill run at shell startup.Create your own Pearl packageAny git repository is already a Pearl package. For instance, in order
to manage a dotfiles repository in Pearl, you just need to change
the Pearl configuration file located in$XDG_CONFIG_HOME/pearl/pearl.conf.Add the following line topearl.conffile:PEARL_PACKAGES={"mydotfiles":{"url":"https://github.com/user/mydotfiles.git","description":"My dotfiles"},}In other words, update thePEARL_PACKAGESdictionary with a new entry containing the
name of the package (i.e.mydotfiles),
the git url (i.e.https://github.com/user/mydotfiles.git) and an optional description.That's it!The package will be ready to be managed by the Pearl system.Structure of a Pearl packageYour own git repository can contain anoptionaldirectory
namedpearl-configused by Pearl to integrate the package with the Pearl environment./ (package root)
│
├── pearl-config (optional directory)
│   │
│   ├── hooks.sh
│   ├── config.sh
│   ├── config.bash
│   ├── config.zsh
│   ├── config.fish
│   ├── config.vim
│   ├── config.el
│   └── package.conf
│
└── (additional package content)The files insidepearl-configare alsooptionalscript/configuration files:hooks.sh- contains thehooks functionsexecuted during theinstall,updateandremoveevents.config.sh- will be sourced whenever a new Bash/Zsh shell is starting up.config.bash- will be sourced whenever a new Bash shell is starting up.config.zsh- will be sourced whenever a new Zsh shell is starting up.config.fish- will be sourced whenever a new Fish shell is starting up.config.vim- will be executed whenever Vim editor is starting up.config.el- will be sourced whenever Emacs editor is starting up.package.conf- contains optional metadata information (name, author, description, keywords, etc) about the package that are useful when indexing the package in a repository list.The order in which theconfig.*files are sourced among multiple installed packages depends on the closure dependency tree,
in other words, if packageAdepends on packageBand both haveconfig.vimfiles, the parent packageBconfig file will be sourced first.The following variables can be used in any of the previous scripts:PEARL_HOME- Pearl location ($XDG_DATA_HOME/pearlwhich by default is$HOME/.local/share/pearl)PEARL_PKGDIR- Pearl package locationPEARL_PKGVARDIR- Pearl package location containing data needed for packagePEARL_PKGNAME- Pearl package namePEARL_PKGREPONAME- Pearl package repo name (useful to detect and interact with packages within the same repo)Additionally, the scripthooks.shcan use the utility functions available inBuavaand Pearlutilsdirectory that
make easier the integration with Pearl ecosystem.Useful examples of Pearl packages can be checked in theOfficial Pearl Hub.The hooks.sh scriptHook functionspost_install- Calledafteran installation of the package occurs.pre_update- Calledbeforean update of the package occurs.post_update- Calledafteran update of the package occurs.pre_remove- Calledbeforea removal of the package occurs.An hooks.sh script examplepost_install(){warn"Remember to setup your config located in: ~/.dotfile"# Do a smart backup before modifying the filebackup${HOME}/.dotfile"# New dotfile">${HOME}/.dotfileifask"Are you sure to link the tmux config?""Y"thenlinktmux"$PEARL_PKGDIR/mytmux.conf"fiinfo"Awesome - new package installed!"return0}post_update(){post_installreturn0}pre_remove(){info"dotfiles package removed"unlinktmux"$PEARL_PKGDIR/mytmux.conf"# Do an idempotent deletedelete${HOME}/.dotfilereturn0}Theinfoandwarnare functions that print a message
using different colors (namely cyan and yellow).Thelinkunlinkare idempotent functions (the result will not change
if the function will be called multiple times) that are able
to link/unlink a config file in order to be loaded at startup by a certain program.Theaskfunction will make installation interactive, asking user whether to link tmux config or not.Thebackupkeeps the last three backups of the file and do not perform backup
if the file has not been modified since the latest backup. Thedeleteis a
function for idempotent remove (it will not raise an error if the file
no longer exist).All these functions belong to theBuavapackage
inutils.shand to the Pearlutils.shscript. You can use them
inside thehooks.shto any hook function.Very important note: All the hook functionsmustbeidempotent(the commands of each hook function must produce the same result even if
the command gets executed multiple times).
All buava commands are idempotent and this will help to write hook functions
very quickly.Note: For OSX system, the GNU versionsedandgrepare automatically
imported inhooks.shand can be directly used if needed.The package.conf filepackage.confis located inpearl-configdirectory and is meant to contain package metadata.
To simplify the creation of new packages, this file is completely optional.
This file may contain name of the package, description, author, os compatibility, license and more.
It can be also used to establish dependencies between packages.Pleasenotethatpackage.confis only meant to encapsulate package information within the package itself
but they are not directly consumed by the Pearl program. In fact, Pearl only reads from thepearl.conffile which is
where the metadata information can be also stored.To give a better idea, take a look at the Pearl Hubrepo.conf.
Therepo-builderis the script responsible to periodically
extract thepackage.confmetadata from each package and update the Pearl Hubrepo.conf.For a local package you can manually include such information directly in thepearl.conffile. This is an example of
package defined inpearl.confwhich depends on thepearl/cmdpackage:PEARL_PACKAGES={'mydotfiles':{"url":'/home/user/my/folder/dotfiles/',"description":"This package contains dotfiles","author":"David Smith <dsmith@abc.com>","depends":("pearl/cmd",)},}If you do not need such features for your package, just ignore this file.Create a Pearl package from a local directoryPearl package system will work even for local directories. This is particularly useful
whenever a Pearl package needs to be tested before pushing to a git repository.For instance, the following lines inpearl.conffile will add a package located in/home/joe/dotfiles:PEARL_PACKAGES={"mydotfiles":{"url":"/home/user/mydotfiles","description":"My dotfiles"},}The directory path must be an absolute path.The package will be ready to be managed by the Pearl system.The directory content can be structured in the exact way as described
in thesectionabove.Use third-party git repository not available in Pearl HubIf you want to use a third-party git repository
that is not available in theOfficial Pearl Hub,
you can:Create your own git repository and use thePEARL_PKGVARDIRdirectory (recommended)Create your own git repository and usegit submodulePoint directly to the third-party git repositoryTo see examples of Pearl packages from third-party git repos take a look at theOfficial Pearl Hub.Create your own git repository and use thePEARL_PKGVARDIRdirectory (recommended)You can use thePEARL_PKGVARDIRdirectory during the installation phase to install the third-party git repository.
This is the best way to incorporate third-party project into Pearl ecosystem.Here it is an example ofhooks.shfile which install the ranger file manager into the directory${PEARL_PKGVARDIR}/ranger:functionpost_install(){install_or_update_git_repohttps://github.com/ranger/ranger.git"${PEARL_PKGVARDIR}/ranger"master}functionpost_update(){post_install}functionpre_remove(){rm-rf${PEARL_PKGVARDIR}/ranger}The functioninstall_or_update_git_repocomes from theBuavalibrary inutils.shwhich is natively available in Pearl during the installation.
You can even use the functionsinstall_git_repoorupdate_git_repowhich respectively install or update the git repository.For a full example take a look at therangerPearl Hub package.Create your own git repository and use git submoduleInside your git repository, you just need to add the third-party git repo as agit submodule.
For instance, to add thepowerlinein your Pearl package,
you can introduce a submodule in themoduledirectory:$>gitsubmoduleaddhttps://github.com/powerline/powerline.gitmoduleThe filesystem structure of the package will become something like this:/ (package root)
│
├── pearl-config   (optional directory)
├── module/        (contains third-party code)
└── (additional package content)Then, you just need to modify the config scripts in order to integrate the third-party
project inside Pearl environment.Point directly to the third-party git repositoryLet's suppose you want to install thevim-railsplugin.
In your Pearl configuration ($XDG_CONFIG_HOME/pearl/pearl.conf), add your new Pearl package:PEARL_PACKAGES={"vim-rails":{"url":"https://github.com/tpope/vim-rails.git","description":"Ruby on Rails power tools"},}Install the package:$>pearlinstallvim-railsVoila', your new vim plugin is ready to be used!This approach is particularly useful whenever you do not need to specify
any pearl config to"enrich"the third-party project inside
the Pearl environment.Create your own Pearl repositoryA Pearl repository is just a git repository containing a file located inpearl-config/pearl.confwith a list of packages. For instance, theOPHrepository is availablehere.In order to use the new repository (i.e. "https://github.com/myrepo/pearl-repo.git"),
update thepearl.conffile by adding the following line:PEARL_REPOS+=("https://github.com/myrepo/pearl-repo.git",)Comparison with alternative solutionsHere we are going to compare Pearl with other solutions according to the following dimensions:ModularAbility of the tool to split configurations and/or programs into different modules.
Its importance is because in case configs are broken you can still manage other modules which you are more confident they works.
For instance, if yourvimconfig does not work you are still able to manage all other dotfiles because they are independent from each other.
Obviously, Pearl, by design, allows modularization through packages.General purposeTools can be eithergeneral(manage any kind of programs) ordotfiles-specific(limited to dotfiles only).SimpleIndicates how easy is to setup and use the tool. Between all tools,Ansibleis the one which has a steep learning curve. Ansible is a powerful software for IT
automation which can be widely used for many use cases.
Despite of this, Ansible has few drawbacks when using it for lightweight forms of automation compared to Pearl:Pearl uses bash for writing simple scripts for automation:it makes easier the integration with other programs in the system (without existing Playbooks may be hard and tedious to achieve this in Ansible);bash is a powerful, accessible and well-known language;Ansible requires way more dependencies than Pearl;Ansible requires knowledge about how Ansible Playbooks works;Pearl uses built-infunctionsandvariableswhich heavily simplify construction of scripts for automation;Pearl makes easier to remove packages and restore the system to an initial state;DiversityIndicates whether the tool handles diverse management for configurations/programs when dealing with heterogeneous machines.
There are multiple ways to handle diversity through Pearl:one way is to create just one package and write bash functions which handle specific logic for each machine.Alternatively, you can create a base package containing common functionality and use a package specific for each machine.
This is possible thanks to the ability to define dependencies between packages.PortableAbility of the tools to be used in multiple platforms. Pearl can be used on both Linux and OSX.ComparisonPearlAnsibleyadmvcshhomesickModularYesYesNoYesYesGeneral purposeYesYesNoNoNoDiversityYesYesYesYesYesSimpleYesNoYesYesYesPortableYesYesYesYesYesTroubleshootingCorrupted Pearl Home directoryQ: What should I do if I accidentally removed files/packages in$PEARL_HOME?A: You can recover the structure of the$PEARL_HOMEby running:$>pearlinitThe command will create all the essential directories and symlinks in$PEARL_HOME.
It is harmless to run theinitcommand multiple times since it is idempotent.Corrupted packageQ: Why I can no longer update/remove a package?A: This is probably because either one of the hook functions
is failing or the package content is corrupted. You can forcely remove the package:$>pearl--forceremove<packagename>which bypass hook functions that are failing. If that does not even work,
you can delete a package by simply removing its directory:$>rm-rf$PEARL_HOME/packages/pearl/<packagename>After that, you can reinstall the package again.
The Pearl packages contain a dedicated directoryvarfor storing
data needed for the package itself.
Thevardata are always managed by the package and they never gets deleted by Pearl
during the package removal.
If you want to delete the content invarpackage:$>rm-rf$PEARL_HOME/var/pearl/<packagename>Package shell variables/functions not visible in current shell after installationQ: Why are not package's environment variables/functions visible in
my current shell after installing/updating the package?A: After package install/update, the variables or
functions related to the current shell and defined inpearl-config/config.*may not be available because a reload of Pearl configuration file is required.
You can fix this by simply run the function:pearl-sourcewhich reloads the configuration.
The use of such function is not always required but depends on
whether the variables/functions involve the current shell where the
packageinstall/updateoccurred (i.e. a new variable defined inconfig.shand the current shell is a bash or zsh). Alternatively, user can always
create a new shell and the package resources will be available as
expected.Error during package installQ: Why Do I get the following error:Erroronexecuting'post_install'hook.Rollingback...A: This occurs when thepost_installhook function fails.
Pearl will attempt to roll back and force a removal of the package. In this way
you can attempt to install the package again once the hook function gets
fixed.Debugging config filesQ: How do I debugconfig.*files when running the corresponding program (i.e.emacs,vim,bash,zsh,fish)?A: Set the environment variablePEARL_DEBUGbefore running the program. For example, to check theconfig.vimfiles run
when starting upvimprogram:PEARL_DEBUG=1vimPearl executable not foundQ: Why do I get this message when opening shells (bash, zsh, fish) or editors (vim, emacs):Pearl error: Could not load pearl package config files. `pearl` executable not found. Please update the PATH variable first."A: This is becausepearlexecutable is required for properly sourcing the pearl packageconfig.*files.
Make sure to add the path location to thePATHin your
favorite shell config file (i.e.~/.bashrc,~/.zshrc,~/.config/fish/config).ContributingYou could help improving Pearl and theOPHin the following ways:Reporting BugsSuggesting EnhancementsWriting CodeDonatingTo sustain the project please consider funding by donations through
theGitHub Sponsors page.AuthorsPearl was originally created byFilippo Squillace (feel.sqoox@gmail.com).Here is a list ofreally appreciated contributors!