1
0
forked from extern/nix-config
donovanglover-nix-config/bin/maid
2017-11-05 21:28:08 -05:00

135 lines
4.4 KiB
Ruby

#!/bin/ruby
##################################################################################
#
# New Start: A modern Arch workflow built with an emphasis on functionality.
# Copyright (C) 2017 Donovan Glover
#
# Maid: Easily move dotfiles from one location to another
# Copyright (C) 2017 Donovan Glover
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
##################################################################################
# Maid is a command line interface to handle the process of moving dotfiles from one
# location to another (i.e. between your local filesystem and the upstream repository)
# NOTE: For Maid to recognize the dotfiles you want, they must be in upstream first
# Use maid add <FULL_PATH> to add a dotfile to upstream (e.g. maid add ~/.vimrc)
# TODO: Use .maidrc to store configuration (?)
# If so, add Maid.init() to create a base configuration
module Maid
REPOSITORY="~/Home/new-start"
def self.maid()
# Store and duplicate the given_command so we can modify it
given_command = ARGV[0].dup
# If no command is given then check all the files for changes
if not given_command then
# We could use self instead of Maid, but this makes things much more declarative
Maid.status()
end
# Otherwise, we can start iterating through the possible commands
# Remove any dashes (this allows us to use both --help and help, for example)
given_command.delete!("-")
if given_command == "help" or given_command == "h" then
Maid.help()
end
if given_command == "up" or given_command == "u" then
Maid.up()
end
if given_command == "down" or given_command == "d" then
Maid.down()
end
if given_command == "status" or given_command == "s" then
Maid.status()
end
if given_command == "diff" or given_command == "f" then
Maid.diff()
end
if given_command == "add" or given_command == "a" then
Maid.add()
end
if given_command == "remove" or given_command == "r" then
Maid.remove()
end
end
def self.help()
puts "Help"
exit 0
end
def self.up()
# If no file was given:
# > For each file in upstream
# > If the file in upstream does not match the file downstream
# > Replace the file upstream with the file downstream
# If a file was given:
# > Look for <filename> with fuzzy matching
# > If exactly one match is found
# > If the file upstream does not match the file downstream
# > Replace the file upstream with the file downstream
# > Else
# > The search was too generic, show all results and ask the
# user to narrow down the search
exit 0
end
def self.down()
# The same as up() but updates the file downstream with the file upstream
exit 0
end
def self.status()
# If no file was given:
# > For each file in upstream, if us != ds then print the file as one that differs
# Note that files downstream may be different or simply may not exist, so handle both cases
# Otherwise a file was given, so show a simple diff between the two files (both ways)
exit 0
end
def self.diff()
# See a comparison between upstream and downstream in vimdiff (same as nvim -d)
exit 0
end
def self.add()
# Add a specific file from downstream to upstream; fails if the file already exists
exit 0
end
def self.remove()
# Remove a specific file from upstream, preventing it from being tracked
exit 0
end
end
Maid.maid()