Giter VIP home page Giter VIP logo

antidot's Introduction

antidot ๐Ÿ  ๐Ÿ”ธ ๐Ÿ’ฅ

Pipeline

Cleans up your $HOME from those pesky dotfiles.

Migration from Pre 0.6.0 Versions

Please backup your environment variable and aliases files (in $XDG_DATA_HOME/antidot/{env,alias}.*). After version 0.6.0 antidot stores env exports and alias definitions in a JSON file and generates from it shell definition files.

Intro

For years I stood by and saw how countless applications populate my home dir with dotfiles.

No more! antidot is a tool to automatically detect and remove dotfiles from $HOME without any risks. It will move files to more appropriate locations (based on XDG base directory specifications). It will also set environment variables, declare aliases and use symlinks to ensure apps can find their files.

Installation

Arch Linux

yay -Sy antidot-bin

Homebrew

brew install doron-cohen/tap/antidot

Go to the releases section and grab the one that fits your OS.

After installing run antidot update to download the latest rules file and you're all set!

How does it Work?

Dotfiles pollution is a complex problem to solve. There are many approaches to solve this annoying issue and antidot is taking the safest one.

We maintain a rule for each dotfile which applies actions when the file is detected. The main goal is to move the files to the most appropriate location while keeping the application working as expected.

There are a few types of actions:

  • Migrate - Move a file to a new location, optionally symlink the old location to the new one (this is for the hardest cases).
  • Delete - Delete a file or a directory (only if it's empty).
  • Export - Export an environment variable.
  • Alias - Set an alias to a command.

Examples

This is the rule for the Docker configuration directory:

  - name: docker
    dotfile:
      name: .docker
      is_dir: true
    actions:
      - type: migrate
        source: ${HOME}/.docker
        dest: ${XDG_CONFIG_HOME}/docker
      - type: export
        key: DOCKER_CONFIG
        value: ${XDG_CONFIG_HOME}/docker

When running antidot clean we will be prompted about this directory:

โฏ ./antidot clean
Rule docker:
  MOVE   /Users/doroncohen/.docker โ†’ /Users/doroncohen/.config/docker
  EXPORT DOCKER_CONFIG="${XDG_CONFIG_HOME}/docker"
? Apply rule docker? (y/N)

Answering yes will move the directory and write the environment variable to a file that can be easily sourced by the shell. Running antidot init will create a shell script that will do just that.

Adding eval "$(antidot init)" to your .bashrc or .zshrc will make sure you shell sessions will see these variables and aliases. In Fish the proper way is to run antidot init | source. You could add it to $__fish_config_dir/conf.d/antidot.fish.

antidot's People

Contributors

alecsferra avatar alexdewar avatar ccoveille avatar cybertailor avatar dependabot[bot] avatar doron-cohen avatar grafcube avatar hollow-owl avatar subraizada3 avatar telans avatar xkww3n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

antidot's Issues

yarn support

just starting to make a tracking ticket so people can share research and ultimately make the correct rule

Make and AUR and I'll test the butter out of it :)

I am using our own TROMjaro.com operating system and I got sick of these .files especially since I test hundreds of applications for our distribution. If you make an AUR for it so I can easily install and manage it (updates and all) I will test this a lot, since I am installing a ton of applications to test for our distro :).

Could be very useful for this little app to get some proper testing.
Thanks a lot for doing this!

npm support

just starting to make a tracking ticket so people can share research and ultimately make the correct rule

macOS binary is blocked on Big Sur.

When I try to open antidot-darwin-amd64.6-amd64 binary on Big Sur (note: I suppose it will fail on Catalina too.), the system blocks it because it comes from 'unidentified developer'. Well-know workaround with right click doesn't help, because (wild guess!) the binary isn't opaqued into .app directory and it doesn't know, how to deal with it.

I tried:

  • running it directly from shell;
  • running it with open command;
  • right-click and select 'Open' from submenu.

The results are here. Mac is, obviously, the one with Intel - I wouldn't try amd64 binary on M1 ;-)

Keep a separate store for environment variables and aliases

In #107 a bug runs over set environment variables and only keeps 2 at a time. This is very bad since these variables are not recoverable without restoring the dotfiles back in the home directory. I will need to keep a separate store that will generate the different formats (bash, fish, zsh etc.).

settings deleted

I was running antidot 0.4.2 until yesterday, I upgraded to 0.6.2

On the next boot, some migrated files appeared again. It wasn't until today that I noticed that none of the migrated environment variables were set anymore.

I just checked $HOME/.local/share/env.sh and it was now empty.

Has anyone experienced this? Do I have to start again with this?

Source files on init only if they exist

I have a test system so I wanted to try antidot on that. Before I ran antidot clean I ran antidot init and added to contents to my .bashrc file

Upon opening a new terminal, it said
bash: /home/rob/.local/share/antidot/alias.sh: No such file or directory
bash: /home/rob/.local/share/antidot/env.sh: No such file or directory

Should these get created when antidot init is run (if they don't exist)?

After running antidot clean I opened a new terminal and got
bash: /home/rob/.local/share/antidot/alias.sh` as only environment variables were needed during this migration, seems that only env.sh was created

Should these get created when antidot init is run (if they don't exist)?

Better looks

I think I should remove the log formatting and quiet all debug logs (unless --verbose is passed). I also want a nicer prompt and action printing.

Support other shells

For now we keep aliases and environment variables in bash format. We should also support Zsh, Fish and other popular shells.

Add trivial rules from Arch wiki

We should add more rules to rules.yaml.

The main source right now is this Arch Linux wiki which is updated from time to time. There are 3 tables on that page: supported, partial and hardcoded. We want to first add the items from the partial table and maybe later look at hardcoded.

There is also some stuff in this Reddit post which may not be in the Arch wiki above.

Remove check for init var value

I did an antidot clean earlier and .gnupg got migrated

I ran gpg and then ~/.gnupg got created as env.sh hadn't been reloaded to set GNUPGHOME

I run source .profile (where I have $(antidot init) and nothing more was loaded, as ANTIDOT_INIT=1 was set, it wasn't loaded again.

In the end, I restarted my computer and it loaded the new variables and it was all working correctly. Is there a way I can load them without restarting my computer?

is:issue is:open Antidot automatically overwrites `antidot/env.sh` but does not tell the user this

.. or instruct them of how to create their own rules in kvstore.json.

I propose we add some comments to the beginning of env.sh and alias.sh:

## WARNING: antidot manages this file internally and will overwrite it
## DO NOT EDIT THIS FILE YOURSELF
# To set your own environment variables, edit `antidot/kvstore.json` and add key-value pairs
# Something something please open a pull request if antidot does not know how to handle a dotfile that we can clean up

I would go further and say that env.sh and alias.sh have no reason to exist, because all the actual information about what to do is stored in kvstore.json as far as I can tell so far. A better implementation would be to have antidot init parse kvstore.json and produce the necessary information to stdout: this would enable supporting more non-POSIX shells, such as ion, more easily.

Better release workflow

Right now our release workflow is kind of broken and half manual. I would like to have a workflow that is creating a PR with the changes to CHANGES.md while creating a draft release. Another step should run application tests with the binaries from the draft release. Once the PR is merged a tag could be set and the release published.

Maybe that's a little overkill but any working automation in that direction will be good enough.

git config migration

git already suports XDG standards, though its not default, the global config file just needs moving

git creats $HOME/.gitconfig for global settings, it also supports $XDG_CONFIG_HOME/config/git/config if the file exists otherwise its default falls back to $HOME/.gitconfig

move $HOME/.gitconfig to $XDG_HOME_CONFIG/.config/git/config

Add a message to source the env and alias files after antidot init

I migrated gnupg (from $HOME/.gnupg to $XDG_CONFIG_HOME/gnupg) thIen ran gpg --list-keys and it created $HOME/.gnupg as GNUPGHOME hadn't been set.

What was required at that point was for me to open a new terminal to refresh env.sh and then GNUPGHOME was set.

I think it would be good to either

  1. warn the user to close and open the terminal after cleanup migration
    or.
  2. source env.sh and aliases.sh after cleanup to load the new variables for immediate use.

Thinking about it, I think the seconds one would be more user friendly as they don't have to do any more to load new variables after cleanup migration

List of files to implement

This is just a general dump of files and folders that could be implemented. Each of these should be moved to their own issue

.xsession-errors
.yarnrc
.xsessionrc
.xinputrc
.Xauthority
.wget-hsts
.sudo_as_admin_successful
.profile
.pam_environment
.notable.json
.lmmsrc.xml
.ICEauthority
.gtkrc-xfce
.gitconfig
.face
.emulator_console_auth_token
.dmrc
.bashrc
.bash_logout
.bash_history
.yarn
.wine
.vscode-oss
.tor-browser
.themes
.ssh
.rednotebook
.pki
.notable
.mume
.linuxmint
.java
.icons
.hplip
.gphoto
.gnome
.dbus
.cinnamon

Exporting wrong XDG envs

Although I have set my envs, they are being reexported in a wrong way. I'm running Zsh.

โฏ echo $XDG_CACHE_HOME
/home/rod/.cache
โฏ eval "$(antidot init)"
โฏ echo $XDG_CACHE_HOME
{XDG_CACHE_HOME:-/home/rod/.cache}
โฏ antidot --version
antidot version 0.6.1
โฏ pwd
/home/rod/{XDG_DATA_HOME:-/home/rod/.local

Tries to move files to / if XDG_CONFIG_HOME is not set.

Downloaded v0.3.0 for amd64, done antidot update, then tried to run it:

user@debian:~$ ./antidot-linux-amd64 clean
Rule gnupg:
  MOVE   /home/user/.gnupg โ†’ /gnupg
  EXPORT GNUPGHOME="${XDG_DATA_HOME}/gnupg"
? Apply rule gnupg? Yes
Failed to run rule gnupg: rename /home/user/.gnupg /gnupg: permission denied

Rule kde:
  MOVE   /home/user/.kde โ†’ /kde
  EXPORT KDEHOME="${XDG_CONFIG_HOME}/kde"
? Apply rule kde? (y/N) 

Rule less:
  MOVE   /home/user/.lesshst โ†’ /less/history
  EXPORT LESSHISTFILE="${XDG_CACHE_HOME}/less/history"
  EXPORT LESSKEY="${XDG_CONFIG_HOME}/less/lesskey"
? Apply rule less? (y/N) 

That looks very wrong.

BTW. I do not have XDG_CONFIG_HOME actually set.

antidot should detect that and not do silly things.

running software via graphical menu

When software is run via the terminal its working well.

When software is run via a graphical menu like with a desktop environment, then I'm finding that the aliases aren't being used.

I manually setup an alias i $HOME/.loca/share/antidot/alias.sh for dosbox then rebooted just to make sure new setting took place.

It worked when I ran dosbox via the command like, it used the moved config file. When I ran dosbox via the menu, its like it didn't use the alias and used the original config file.

Have you had any experience like this?

FYI about .gnupg after migration

This will only happen on some linux distrobutions, not all (so I have read). I don't think anything can be done about it.

After migrating .gnupg, upon reboot it will create a new $HOME/.gnupg directory which has one empty directy in it, though continue to use $XDG_CONFIG_HOME/gnupg when using the gpg command.

I get this with Xubuntu 18.04.5

nvidia GL shader cache dot directory

I don't know where to add this, so I'll try it here.

Nvidia has a directory it uses for cache called GLCache , by default it is stored in ~/.nv

To move this directory the environment variable __GL_SHADER_DISK_CACHE_PATH can be set to $XDG_CACHE_HOME/nv for it to be with the other nvidia cache directories.

Is this where I can add dotfiles for moving?

Thanks,
Rob

.Xauthority

.Xauthority can be tricky. It can be moved with XAUTHORITY envorment variable, except that there are couple of desktop environments that don't support this.

lightdm is oen, which is the default for Xubuntu. If XAUTHORITY is set, then the user won't be able to login.

A workaround this is to edit the file /etc/lightdm/lightdm.conf and add or edit the line
user-authority-in-system-dir=true
It seems that either this line is not there, or its set to false.

I found it in this page https://askubuntu.com/questions/960793/whats-the-right-place-to-set-the-xauthority-environment-variable

I then deleted $HOME/.Xauthority and rebooted, then it was in /var/run/lightdm/user/Xauthority

I think this variable would have to be set in .profile, so that it would be available during bootup, before .bashrc is processed

theano support

I ran software than used theano (a python tool) and it left a directory in $HOME/.theano
From what I understand, its a cache directory to pre-compiled scripts. If its deleted, it will be created on the next time its run.

I think it should belong in $XDG_CACHE_CONFIG/theano

https://theano-pymc.readthedocs.io/en/latest/library/config.html#envvar-THEANO_FLAGS

From the instructions, I moved it using the following envionment variable
THEANO_FLAGS="base_compiledir=$XDG_CACHE_HOME/theano"

App testing framework

We should have a testing framework for ensuring that rules work correctly and we don't break anything. For example, for this cargo rule:

  - name: cargo_home
    description: Rust Cargo home dir
    dotfile:
      name: .cargo
      is_dir: true
    actions:
      - type: migrate
        source: ${HOME}/.cargo
        dest: ${XDG_DATA_HOME}/cargo
        symlink: false
      - type: export
        key: CARGO_HOME
        value: ${XDG_DATA_HOME}/cargo

should be tested like:

  1. running cargo commands.
  2. ensuring the dotfile is there.
  3. running antidot.
  4. running cargo commands that interact with it's dotfiles (like reading or writing configuration).
  5. ensure the cargo dotfile isn't there and that it did interact with it's dotfile in the new path.

This could be done using the Github Actions platform on both Linux and Mac machines. Also, defining tests should be easy (app installation command, pre-command, post-command, validation command). It could be written in Bash but Go is also an option.

Of course testing interactive applications will pose a bigger challenge or maybe even be too expensive to do.

Add a note or warning to a rule to be printed to the user

Sometimes during a migration, a command has to be run e.g. to reset a system running

I just tried to manually migrate gnupg from ~/.gnupg to ~/.local/share/gnupg and for one of my tests, I had to run "gpgconf --kill gpg-agent" before I was able to create a private key. They key agent was still looking in the old directory.

Does antidot support the running of commands during migration?

add keychain support

it seems to be an alias
$ keychain --absolute --dir "$XDG_RUNTIME_DIR"/keychain womp womp

Option to use ~/.pam_environment

This can be useful for setting environment variables that need to affect your login shell before your login shell has started. For example Zsh allows you to set a $ZDOTDIR variable to modify where it stores its configuration which can be achieved as follows:

~/.pam_environment:

XDG_CONFIG_HOME   DEFAULT=@{HOME}/.config
ZDOTDIR	DEFAULT=${XDG_CONFIG_HOME}/zsh

Fallback to common XDG values when not set with notification to user

I don;t have XDG_DATA_HOME (or any of the XDG directories) set and it gave the output below.

For cargo, it wanted to move it from /home/rob/.cargo to /cargo, shouldn't this be XDG_DATA_HOME/cargo or if XDG_DATA_HOME is not set, ~/.local/share. Does XDG_DATA_HOME fall back to ~/.local.share if its not set?

Rule cargo_home:
MOVE /home/rob/.cargo โ†’ /cargo
EXPORT CARGO_HOME="${XDG_DATA_HOME}/cargo"
? Apply rule cargo_home? No

Rule less:
MOVE /home/rob/.lesshst โ†’ /less/history
EXPORT LESSHISTFILE="${XDG_CACHE_HOME}/less/history"
EXPORT LESSKEY="${XDG_CONFIG_HOME}/less/lesskey"
? Apply rule less? No

Rule cuda:
MOVE /home/rob/.nv โ†’ /nv
EXPORT CUDA_CACHE_PATH="${XDG_CACHE_HOME}/nv"
? Apply rule cuda? No

Rule nvidia-settings:
MOVE /home/rob/.nvidia-settings-rc โ†’ /nvidia/settings
ALIAS nvidia-settings="nvidia-settings --config=${XDG_CONFIG_HOME}/nvidia/settings"
? Apply rule nvidia-settings? No

Rule parallel:
MOVE /home/rob/.parallel โ†’ /parallel
EXPORT PARALLEL_HOME="${XDG_CONFIG_HOME}/parallel"
? Apply rule parallel? No

Rule rustup:
MOVE /home/rob/.rustup โ†’ /rustup
EXPORT RUSTUP_HOME="${XDG_DATA_HOME}/rustup"
? Apply rule rustup? No

env.fish with more than two rules

I encountered two issues in fish:

  1. Applying more than 2 rules with EXPORT would write the third rule over the second in env.fish
  2. antidot clean asks me to run eval "$(antidot init)", which in fish it would be eval (antidot init) - but running that gives error fish: 'end' outside of a block

SHELL=/usr/bin/fish
fish, version 3.1.2
antidot version 0.5.0

I use antidot init in .profile and .bashrc

This is more open for discussion and FYI on my experience as peoples usage needs may vary, depending on computer setup.

I have found that I have to set antidot init in .profile and .bashrc

I have to put it in .profile as __GL_SHADER_DISK_CACHE_PATH has to be set int there after migration. If it isn't, then ~/.nv gets created again

I also set it in .bashrc as if I run antidot clean, then I only have to open a new terminal window to load the new variables and aliases. For .profile I would have to logout then login, or reboot to refresh new variables and aliases after migration

trouble adding antodot to run in .bashrc

I've been having trouble with adding $(~/bin/antidot init) in .bashrc

When I do, I get the error message
if : command not found
at the beginning of each terminal I open

So for now, I have copied and pasted the code that antidot init prints into my .bashrc file

Am I making an error or is this a bug?
I'm running bash 4.4.20 with xubuntu 18.04.5

.ICEauthority

.ICEauthority can be moved using the variable ICEAUTHORITY

libice 1.0.10 implements XDG standards, so when $HOME/.ICEauthority is deleted and the computer is rebooted, it creates $XDG_RUNTIME_DIR/ICEauthority
https://gitlab.freedesktop.org/xorg/lib/libice/-/issues/2
https://gitlab.freedesktop.org/xorg/lib/libice/-/commit/b484311c929a1b64966d89da92fafce7263006e1

Now the only problem with this is that I also get an empty $HOME/.ICEauthority as well as the file $XDG_RUNTIME_DIR/ICEauthority being used.

I have submitted a bug report about this
https://gitlab.freedesktop.org/xorg/lib/libice/-/issues/9

When I tried setting ICEAUTHORITY I set it in .profile, I think it would have to set to be available during bootup, before .bashrc gets processed.

support bash history

.bash_history can be moved by setting HISTFILE

I know its more of a system file than an application file, are these something you'd consider migrating too?

I suggest moving to $XDG_CACHE_HOME/bash/bash_history
or to
$XDG_CACHE_HOME/bash/history

see "help history" for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.