import os
import sys

from virtualfish.loader import load

XDG_CONFIG_HOME = os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
INSTALL_DIR = os.path.join(XDG_CONFIG_HOME, "fish", "conf.d")
INSTALL_FILE = os.path.join(INSTALL_DIR, "virtualfish-loader.fish")


def install(plugins):
    # Calculate the script to write.
    lines = load(plugins)

    # Write the script.
    os.makedirs(INSTALL_DIR, exist_ok=True)
    with open(INSTALL_FILE, "w") as f:
        f.write("\n".join(lines))


def uninstall():
    os.unlink(INSTALL_FILE)


if __name__ == "__main__" and sys.argv[1] == "uninstall":
    uninstall()

@@ -540,16 +540,931 @@
 FILE)%0A%0A%0A
+def addplugins(plugins=()):%0A    with open(INSTALL_FILE, 'r') as fp:%0A        conf = fp.readlines()%0A        position = -1%0A        for i, line in enumerate(conf):%0A            if %22virtual.fish%22 in line:%0A                position = i%0A                continue%0A            for j, plugin in enumerate(plugins):%0A                if plugin+%22.fish%22 in line:%0A                    plugins.pop(j)%0A        for i, p in enumerate(load(plugins, full_install=False)):%0A            conf.insert(position+1+i, p+'%5Cn')%0A    with open(INSTALL_FILE, 'w') as fp:%0A        fp.writelines(conf)%0A%0A%0Adef rmplugins(plugins=()):%0A    with open(INSTALL_FILE, 'r') as fp:%0A        conf = fp.readlines()%0A        position = -1%0A        for i, line in enumerate(conf):%0A            for j, plugin in enumerate(plugins):%0A                if plugin+%22.fish%22 in line:%0A                    conf.pop(i)%0A    with open(INSTALL_FILE, 'w') as fp:%0A        fp.writelines(conf)%0A%0A%0A
 if __nam
@@ -1484,12 +1484,16 @@
 n__%22
- and
+:%0A    if
  sys
@@ -1517,16 +1517,20 @@
 stall%22:%0A
+    
     unin
@@ -1537,8 +1537,148 @@
 stall()%0A
+    elif sys.argv%5B1%5D == %22addplugins%22:%0A        addplugins(sys.argv%5B2:%5D)%0A    elif sys.argv%5B1%5D == %22rmplugins%22:%0A        rmplugins(sys.argv%5B2:%5D)%0A

Add rmplugins and addplugins functions to installer