@@ -2,7 +2,8 @@ v0.3.1 (unreleased): | |||||
- Added a `--prune` flag to delete remote-tracking branches that no longer | - Added a `--prune` flag to delete remote-tracking branches that no longer | ||||
exist on their remote after fetching. | exist on their remote after fetching. | ||||
- Added a '--bookmark-file' option to support multiple bookmark config files. | |||||
- Added a `--bookmark-file` flag to support multiple bookmark config files. | |||||
- Added a `--cleanup` flag to remove old bookmarks that don't exist. | |||||
- Cleaned up the bookmark file format, fixing a related Windows bug. The script | - Cleaned up the bookmark file format, fixing a related Windows bug. The script | ||||
will automatically migrate to the new one. | will automatically migrate to the new one. | ||||
- Fixed a bug related to Python 3 compatibility. | - Fixed a bug related to Python 3 compatibility. | ||||
@@ -12,7 +12,7 @@ from colorama import Fore, Style | |||||
from .migrate import run_migrations | from .migrate import run_migrations | ||||
__all__ = ["get_default_config_path", "get_bookmarks", "add_bookmarks", | __all__ = ["get_default_config_path", "get_bookmarks", "add_bookmarks", | ||||
"delete_bookmarks", "list_bookmarks"] | |||||
"delete_bookmarks", "list_bookmarks", "clean_bookmarks"] | |||||
YELLOW = Fore.YELLOW + Style.BRIGHT | YELLOW = Fore.YELLOW + Style.BRIGHT | ||||
RED = Fore.RED + Style.BRIGHT | RED = Fore.RED + Style.BRIGHT | ||||
@@ -106,10 +106,27 @@ def delete_bookmarks(paths, config_path=None): | |||||
def list_bookmarks(config_path=None): | def list_bookmarks(config_path=None): | ||||
"""Print all of our current bookmarks.""" | """Print all of our current bookmarks.""" | ||||
bookmarks = get_bookmarks(config_path=config_path) | |||||
bookmarks = _load_config_file(config_path) | |||||
if bookmarks: | if bookmarks: | ||||
print(YELLOW + "Current bookmarks:") | print(YELLOW + "Current bookmarks:") | ||||
for bookmark_path in bookmarks: | for bookmark_path in bookmarks: | ||||
print(INDENT1, bookmark_path) | print(INDENT1, bookmark_path) | ||||
else: | else: | ||||
print("You have no bookmarks to display.") | print("You have no bookmarks to display.") | ||||
def clean_bookmarks(config_path=None): | |||||
"""Delete any bookmarks that don't exist.""" | |||||
bookmarks = _load_config_file(config_path) | |||||
if not bookmarks: | |||||
return | |||||
delete = [path for path in bookmarks if not os.path.isdir(path)] | |||||
if not delete: | |||||
return | |||||
bookmarks = [path for path in bookmarks if path not in delete] | |||||
_save_config_file(bookmarks, config_path) | |||||
print(YELLOW + "Deleted bookmarks:") | |||||
for path in delete: | |||||
print(INDENT1, path) |
@@ -13,7 +13,7 @@ from colorama import init as color_init, Fore, Style | |||||
from . import __version__ | from . import __version__ | ||||
from .config import (get_default_config_path, get_bookmarks, add_bookmarks, | from .config import (get_default_config_path, get_bookmarks, add_bookmarks, | ||||
delete_bookmarks, list_bookmarks) | |||||
delete_bookmarks, list_bookmarks, clean_bookmarks) | |||||
from .update import update_bookmarks, update_directories | from .update import update_bookmarks, update_directories | ||||
def _decode(path): | def _decode(path): | ||||
@@ -64,6 +64,9 @@ def main(): | |||||
'-l', '--list', dest="list_bookmarks", action="store_true", | '-l', '--list', dest="list_bookmarks", action="store_true", | ||||
help="list current bookmarks") | help="list current bookmarks") | ||||
group_b.add_argument( | group_b.add_argument( | ||||
'-e', '--clean', '--cleanup', dest="clean_bookmarks", | |||||
action="store_true", help="delete any bookmarks that don't exist") | |||||
group_b.add_argument( | |||||
'-b', '--bookmark-file', nargs="?", metavar="path", type=_decode, | '-b', '--bookmark-file', nargs="?", metavar="path", type=_decode, | ||||
help="use a specific bookmark config file (default: {0})".format( | help="use a specific bookmark config file (default: {0})".format( | ||||
get_default_config_path())) | get_default_config_path())) | ||||
@@ -107,6 +110,9 @@ def main(): | |||||
if args.list_bookmarks: | if args.list_bookmarks: | ||||
list_bookmarks(args.bookmark_file) | list_bookmarks(args.bookmark_file) | ||||
acted = True | acted = True | ||||
if args.clean_bookmarks: | |||||
clean_bookmarks(args.bookmark_file) | |||||
acted = True | |||||
if args.directories_to_update: | if args.directories_to_update: | ||||
update_directories(args.directories_to_update, update_args) | update_directories(args.directories_to_update, update_args) | ||||
acted = True | acted = True | ||||