-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can this utility comment out keys? #97
Comments
That is not supported at present, though would be useful and is already mentioned in the TODO file |
Gotcha, I read the TODO, I will work on this. I have been meaning to create something like crudini for a while I manage *nix provisioning configs and I've gotten tired of doing it with plain bash. It takes way too much fiddling with sed/awk to manipulate ini files. Just so we're clear. use case 1 [a-section]
# a-key = foo to: [a-section]
a-key = foo use case 2 [a-section]
# a-key = foo to: [a-section]
# a-key = bar use case 3 [a-section]
# a-key = foo to: [a-section]
# a-key = foo
# b-key = bar I guess one could also comment out sections, but most often than not I am working with already made configs with sections. |
Related issue is issue #22 |
I'm having a similar issue when modifying php.ini files:
It would be great to be able to uncomment the above configuration line. Currently crudini puts the configuration in the bottom of the file. However, the bottom of the file has an include statement like:
Because of this include statement, the namespace changes from |
@nicodemuz on my admin stuff I just ended up using sed and made a custom bash function. I have a bunch of custom libraries in bash with utility functions, I will admit I am not a fan a bash but you can't beat the simplicity once you learn it, I would say with less than a dozen one liners using sed/awk and other linux utils you could replace crudini all together to manage config files of all kinds. With this function you can comment and uncomment any line in place: comments.sh #!/bin/bash
comment_uncomment() {
flag=$1
comment_char=$2
string_to_match=$3
file_path=$4
if [ "$flag" == "comment" ]; then
sed -i "/^[[:space:]]*[^$comment_char]/ s/$string_to_match/$comment_char&/" "$file_path"
echo "Lines containing '$string_to_match' commented in $file_path"
elif [ "$flag" == "uncomment" ]; then
sed -i -E "s/^($comment_char *?)(.*$string_to_match.*)$/\2/g" "$file_path"
echo "Lines containing '$string_to_match' uncommented in $file_path"
else
echo "Invalid flag. Please use 'comment' or 'uncomment'."
fi
}
# Usage: comment_uncomment flag comment_char string_to_match file_path
# Example usage:
# comment_uncomment comment ";" "Default Unit: seconds" "example.txt"
# comment_uncomment uncomment "#" "partial match" "example.txt"
comment_uncomment "$1" "$2" "$3" "$4" If you save file as comments.sh and chmod to be executable you can call it as follows:
In addition you can save your sh file in path and you could call it from anywhere, also uncomment and comment flags could be shortened to your liking. Hope this help you. |
@nicodemuz Interesting.
|
For my use case, I would personally prefer the first option, as then the related php ini comment would be above the configuration. |
Can I say comment or uncomment "some_key" from X file?
The text was updated successfully, but these errors were encountered: