import re
import subprocess
import sys
+import shutil
from collections import OrderedDict
from distutils.version import LooseVersion as Version
-h, --help get this small help
-c, --change reload current setup
-s, --save <profile> save your current setup to profile <profile>
+-r, --remove <profile> remove profile <profile>
-l, --load <profile> load profile <profile>
-d, --default <profile> make profile <profile> the default profile
--skip-options <option> comma separated list of xrandr arguments (e.g. "gamma")
def main(argv):
try:
- options = dict(getopt.getopt(argv[1:], "s:l:d:cfh", [ "dry-run", "change", "default=", "save=", "load=", "force", "fingerprint", "config", "debug", "skip-options=", "help" ])[0])
+ options = dict(getopt.getopt(argv[1:], "s:r:l:d:cfh", [ "dry-run", "change", "default=", "save=", "remove=", "load=", "force", "fingerprint", "config", "debug", "skip-options=", "help" ])[0])
except getopt.GetoptError as e:
print("Failed to parse options: {0}.\n"
"Use --help to get usage information.".format(str(e)),
print("Saved current configuration as profile '%s'" % options["--save"])
sys.exit(0)
+ if "-r" in options:
+ options["--remove"] = options["-r"]
+ if "--remove" in options:
+ if options["--remove"] in ( x[0] for x in virtual_profiles ):
+ raise AutorandrException("Cannot remove profile '%s':\nThis configuration name is a reserved virtual configuration." % options["--remove"])
+ if options["--remove"] not in profiles.keys():
+ raise AutorandrException("Cannot remove profile '%s':\nThis profile does not exist." % options["--remove"])
+ try:
+ profile_folder = os.path.join(profile_path, options["--remove"])
+ shutil.rmtree(profile_folder)
+ except Exception as e:
+ raise AutorandrException("Failed to remove profile '%s'" % (options["--remove"],), e)
+ print("Removed profile '%s'" % options["--remove"])
+ sys.exit(0)
+
if "-h" in options or "--help" in options:
exit_help()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
- opts="-h -c -s -l -d"
- lopts="--help --change --save --load --default --force --fingerprint --config --dry-run"
+ opts="-h -c -s -r -l -d"
+ lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
if [ -d ~/.autorandr ]; then
prfls="`find ~/.autorandr/* -maxdepth 1 -type d -printf '%f\n'`"
elif [ -d ~/.config/autorandr ]; then
esac
case "${prev}" in
- -l|--load|-d|--default)
+ -r|--remove|-l|--load|-d|--default)
COMPREPLY=( $( compgen -W "${prfls}" -- $cur ) )
return 0
;;