nix-config/src/maid.cr

116 lines
3.5 KiB
Crystal
Raw Normal View History

2017-11-14 12:57:13 +01:00
##################################################################################
#
# 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
require "file_utils"
require "../lib/trucolor"
2017-11-14 12:57:13 +01:00
module Maid
UPSTREAM = "/Home/new-start/dotfiles"
2017-11-14 19:36:59 +01:00
extend self
def maid()
2017-11-14 12:57:13 +01:00
Maid.status() if ARGV.size() == 0
case ARGV[0].delete("-")
when "help", "h"; Maid.help()
when "up", "u"; Maid.up()
when "down", "d"; Maid.down()
when "status", "s"; Maid.status()
when "diff", "f"; Maid.diff()
when "add", "a"; Maid.add()
when "remove", "r"; Maid.remove()
end
end
2017-11-14 19:36:59 +01:00
def help()
2017-11-14 19:55:10 +01:00
puts Trucolor.format({125, 255, 0}, "Usage: maid [command]")
_hr("Always used:")
_hc("up", "Replace the file upstream with the file downstream")
_hc("down", "Replace the file downstream with the file upstream")
_hc("status", "List the files that aren't in sync with upstream")
_hr("Sometimes used:")
_hc("diff", "View the lines that differ between upstream and downstream")
_hr("Rarely used:")
_hc("add", "Copy a file from downstream to upstream")
_hc("remove", "Removes a file from upstream, preventing it from being tracked")
_hn("Ideally you should only edit files locally (i.e. not upstream)")
_hn("Then pushing your changes is as simple as typing 'maid up'!")
2017-11-14 12:57:13 +01:00
exit 0
end
2017-11-14 19:55:10 +01:00
private def _hc(command, description)
puts Trucolor.format({255, 55, 225}, " #{command.ljust(14, ' ')}#{description}")
end
private def _hr(message)
puts Trucolor.format({12, 155, 255}, " #{message}")
end
private def _hn(note)
puts Trucolor.format({255, 128, 10}, "#{note}")
end
2017-11-14 19:36:59 +01:00
def up()
2017-11-14 12:57:13 +01:00
puts "Up"
exit 0
end
2017-11-14 19:36:59 +01:00
def down()
2017-11-14 12:57:13 +01:00
puts "Down"
exit 0
end
2017-11-14 19:36:59 +01:00
def status()
2017-11-14 12:57:13 +01:00
puts "Status"
exit 0
end
2017-11-14 19:36:59 +01:00
def diff()
2017-11-14 12:57:13 +01:00
puts "Diff"
exit 0
end
2017-11-14 19:36:59 +01:00
def add()
2017-11-14 12:57:13 +01:00
puts "Add"
exit 0
end
2017-11-14 19:36:59 +01:00
def remove()
2017-11-14 12:57:13 +01:00
puts "Remove"
exit 0
end
end
Maid.maid()