项目作者: snakypy

项目描述 :
:snake: :package: :page_facing_up: Dotctrl is a package for managing your dotfiles (and more) on Linux.
高级语言: Python
项目地址: git://github.com/snakypy/dotctrl.git
创建时间: 2020-03-24T00:50:40Z
项目社区:https://github.com/snakypy/dotctrl

开源协议:MIT License

下载


Languages: Português Brasileiro



Dotctrl

The “dotfiles” control tool.

Tests
Python Versions
Updates
Python Whell
PyPI
PyPI - Implementation
Isort
Mypy
Code style: Black
MaxLength
PyPI - Downloads
GitHub license

PEP8


Built with ❤︎ by:
William Canin in free time,
to the sound of the playlist: Bursting Of The Tympanum







About

Initially, Dotctrl was created just to control “dotfiles files”, however,
in the course, it became more than that.
Dotctrl is now a maintainer of any file and folder type within its own
private repository.

This is too much!

Dotctrl will manage the elements of the user’s HOME directory; running on
top of a configuration file (dotctrl.json) that contains the paths to the
origin location of the elements.

All elements managed by Dotctrl are kept in the repository/folder
dotctrl“.

See a demo:

Features

  • language support: American English and Brazilian Portuguese;
  • create (or not) multiple repositories for your elements;
  • abandon the creation of huge manual symlinks;
  • will store the same path structure as your original location ($HOME);
  • manage single or bulk elements;
  • restore repository elements to their original location with a single command;
  • and much more :)

Requirements

To work properly, you will first need:

Installing

It’s time to install Dotctrl. To do this, do:

  1. python3 -m pip install dotctrl --user

NOTE: If you are installing in the user’s local environment, be sure to add
the environment variables to the zshrc file
or .bashrc file.

Using

init

After installing the package, you need to create the Dotctrl repository in
an empty folder in your
choice. We always recommend creating /home or /Users in the root
directory, because creating in the user’s folder can be
lost if user is deleted. With that, see the example below:

Linux:

  1. sudo mkdir -p /home/.dotfiles; cd $_
  2. sudo chown -R $(whoami) /home/.dotfiles
  3. sudo chmod -R 700 /home/.dotfiles
  4. dotctrl init

macOS:

  1. sudo mkdir -p /Users/.dotfiles; cd $_
  2. sudo chown -R $(id -un) /Users/.dotfiles
  3. sudo chmod -R 700 /Users/.dotfiles
  4. dotctrl init

—auto

You can bypass all of these commands above using the --auto flag. Dotctrl
will automatically create a base
directory to store the data, however you MUST have sudo permission.

We strongly recommend using this option if you have permission.

  1. dotctrl init --auto

—git

This flag causes Dotctrl to create a git repository
within the Dotctrl repository.

  1. dotctrl init --git

You can also combine this flag with the --auto flag:

  1. dotctrl init --auto --git

pull

With the base already created, it’s time for you to PULL the elements to the
base of Dotctrl with the pull command.

Pull single element to the Dotctrl repository:

  1. dotctrl pull --e .zprofile

If you want to do a massive pull, do:

  1. dotctrl pull

Note: This option is only possible if you pass the
elements manually in the dotctrl.json file or have
not cleaned the registry.

After pulling the element(s), create symlinks to them in their original
locations:

  1. dotctrl link --e .zprofile

If you want to perform a massive link, do:

  1. dotctrl link

Note: This option is only possible if you pass the
elements manually in the dotctrl.json file or have
not cleaned the record.

Unlink the repository element with the source location:

  1. dotctrl unlink --e .zprofile

If you want to unlink elements massively, do:

  1. dotctrl unlink

Note: This option is only possible if you pass the
elements manually in the dotctrl.json file or
have not cleaned the record.

restore

This command will take an element from the Dotctrl repository and restore
it to its original location:

  1. dotctrl restore --e .zprofile

If you want to perform a massive restore, do:

  1. dotctrl restore

Note: By default, when restoring element(s) to their original location,
Dotctrl does NOT remove the elements from the registry
(dotctrl.json). To clean, see —autoclean.

repo

This command brings information from the repository, see below some of its
subcommands:

—check

Check to see if there are elements to link:

  1. dotctrl repo --check

—ls

Check the elements already imported into the Dotctrl repository.

  1. dotctrl repo --ls

—info

With the command below you can see some information from the Dotctrl
repository, such as the number of folders and files,
the absolute path of the repository and if the environment variable
DOTCTRL_PATH is active.

  1. dotctrl repo --info

find

Searches for any element within the Dotctrl repository. To do this, use
the command:

  1. dotctrl find --name .zprofile

Note: Enclose the element to be found with double quotes if it has spaces
in the name.

config

This command will manipulate the Dotctrl configuration file, see below
some of its subcommands.

—autoclean

Clean up the elements present in the Dotctrl configuration file.
Any element that is present in the Dotctrl configuration file and does not
EXIST in the repository will be eliminated from the configuration file.

Usually --autoclean is used after using the command to restore
elements.

  1. dotctrl config --autoclean

—view

Take a peek at the Dotctrl configuration file from the terminal.

—open

Allows you to edit the Dotctrl configuration file in the terminal itself
using the command:

  1. dotctrl config --open

Note: It defaults to the vim editor, if not, it will try to use nano,
emacs or micro.

—lang

Use this flag to change the language of Dotctrl. Dotctrl currently
supports 2 (two) languages, they are: American English and
Brazilian Portuguese. When using the command below, it will show a list
for you to choose which language you want to use. The change is instantaneous.

  1. dotctrl config --lang

Global flags

—e (—element)

The —e or —element flag is responsible for handling a specific
element of the Dotctrl repository.

This flag must receive an element without the absolute path, only the relative
one from $HOME.

Examples:

  • dotctrl pull --e .zprofile
  • dotctrl link --e .zprofile
  • dotctrl unlink --e .zprofile
  • dotctrl restore --e .zprofile

If the element has spaces in the name, enclose it in double quotes. Example:
dotctrl pull --e "file legal.txt file"

—f (—force)

The —f or —force flag literally forces the use of the command,
preventing something from preventing its completion. This option is present in
all commands that manipulate elements, these commands are: pull, link,
unlink and restore.

Configuration file (dotctrl.json)

This is an example of a complete Dotctrl configuration file
(dotctrl.json) structure:

  1. {
  2. "dotctrl": {
  3. "config": {
  4. "editor": "vim",
  5. "language": "pt_BR"
  6. },
  7. "elements": [
  8. ".zshrc",
  9. ".config/xfce4/terminal/terminalrc",
  10. ".config/Code/User",
  11. "Images/Wedding"
  12. ]
  13. }
  14. }

Environment Variable

By default, Dotctrl works with multiple directories, which makes you need
to use it in a certain directory you created for your elements.

If you want to use Dotctrl in any PATH, you need to create an environment
variable that Dotctrl makes available. This environment variable is
DOTCTRL_PATH.

You must enter the DOTCTRL_PATH variable in your operating system containing
the directory where your dotfiles will be. For example, in your .bashrc or
.zshrc file:

Linux:

  1. export DOTCTRL_PATH="/home/.dotfiles"

or

macOS:

  1. export DOTCTRL_PATH="/Users/.dotfiles"

NOTE: Remember, when creating this environment variable, you will not be
able to create other repositories for Dotctrl.

Updating

If Dotctrl has new features, please update the command line below:

  1. python3 -m pip install dotctrl -U --user

More commands

For more command information, use:

  1. dotctrl [--help | -h]

Extras

Deploy and Clone from Dotctrl repository

Now that you have control of your elements, it’s time to deploy them to a git
service.
This example below will show you how to deploy and clone on
GitHub.

1 - Deploy:

A - Entering the root folder created by Dotctrl:

Linux:

  1. cd /home/.dotfiles

macOS:

  1. cd /Users/.dotfiles

B - Creating git repository, commit and saving (push)

  1. git remote add origin git@github.com:<YOUR USER>/dotfiles.git
  2. git init
  3. git add .
  4. git commit -m "Update"
  5. git push origin main

2 - Clone:

You can also clone any directory of your choice, but we’ll keep the example
build directory above. Follow the steps:

Linux:

  1. sudo mkdir -p /home/.dotfiles
  2. sudo chmod -R 770 /home/.dotfiles
  3. cd /home/.dotfiles
  4. git clone git@github.com:<YOUR USER>/dotfiles.git .
  5. dotctrl link --f

macOS:

  1. sudo mkdir -p /Users/.dotfiles
  2. sudo chmod -R 770 /Users/.dotfiles
  3. cd /Users/.dotfiles
  4. git clone git@github.com:<YOUR USER>/dotfiles.git .
  5. dotctrl link --f

Donation

Click on the image below to be redirected to the donation forms:

It is very important that you make a donation to motivate further development
of Dotctrl. :)

License

The project is available as open source under the terms of the
MIT License ©

Credits

See, AUTHORS.