Created
May 3, 2024 14:52
-
-
Save ktemkin/9d35bcab82122385b5455f9d2138cdd0 to your computer and use it in GitHub Desktop.
hack to let you use unquoted flake attr refs in xonsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Input transformer that automatically quotes mid-word #s for e.g. nix. """ | |
from xonsh.events import events | |
@events.on_transform_command | |
def _autoquote_for_nix(cmd): | |
new_command = [] | |
# Process each word individually. | |
words = cmd.strip().split(" ") | |
for word in words: | |
# If this is unquoted, and it has a comment in it without spaces, | |
# consider it something that we should auto-quote. | |
has_comment = '#' in word | |
is_comment = word.startswith("#") | |
is_quoted = ('"' in word) or ("'" in word) | |
if has_comment and not is_comment and not is_quoted: | |
word = '"' + word + '"' | |
new_command.append(word) | |
# Reconstruct our command. | |
return " ".join(new_command) + "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment