mirror of
https://github.com/scopatz/nanorc
synced 2025-06-20 13:40:07 +02:00
Better sed
This commit is contained in:
parent
5d5521c048
commit
7c7fe0928d
27
install.sh
27
install.sh
@ -34,8 +34,8 @@ G_DEPS="unzip sed"
|
||||
G_FILE="${HOME}/.nanorc"
|
||||
G_REPO_MASTER="https://github.com/scopatz/nanorc/archive/master.zip"
|
||||
G_REPO_RELEASE="https://github.com/scopatz/nanorc/archive/${G_VERSION}.zip"
|
||||
G_NANO_VERSION="4.6.0"
|
||||
G_NANO_NRC_DIR=""
|
||||
# G_NANO_VERSION="4.6.0"
|
||||
# G_NANO_NRC_DIR=""
|
||||
unset G_LITE G_UNSTABLE G_VERBOSE G_DIR G_THEME
|
||||
|
||||
# Exit Values Help
|
||||
@ -175,6 +175,9 @@ f_install(){
|
||||
begin="# BEGIN"
|
||||
end="# END"
|
||||
theme="${G_DIR}/themes/${G_THEME}/"
|
||||
# Sed rules : skip over the line "$begin" tag and before "$end" tag
|
||||
sed_lite="$(printf "/%s/,/%s/{ /%s/n /%s/ !{ s/*// r '%s/config' r '%s' d }}" "$begin" "$end" "$begin" "$end" "$theme" "$(f_get_nanorc)")"
|
||||
sed_no_lite="$(printf "/%s/,/%s/{ /%s/n /%s/ !{ s/*// r '%s/config' r 'include /nanorc/*' d }}" "$begin" "$end" "$begin" "$end" "$theme")"
|
||||
|
||||
if cd "$HOME"; then
|
||||
printf "\n Error: Cannot open or access '%s' directory." "${HOME}"
|
||||
@ -215,25 +218,9 @@ f_install(){
|
||||
printf "\n %s \n %s \n" "$begin" "$end" >> "$G_FILE"
|
||||
|
||||
if [ "$G_LITE" = true ]; then
|
||||
sed -n -i.bkp '/'"$begin"'/,/'"$end"'/ {
|
||||
/'"$begin"'/n # skip over the line that has "$begin" on it
|
||||
/'"$end"'/ !{ # skip over the line that has "$end" on it
|
||||
s/*//
|
||||
r '"${theme}/config"'
|
||||
r f_get_nanorc
|
||||
d
|
||||
}
|
||||
}' "$G_FILE"
|
||||
sed -n -i.bkp '$sed_lite' "$G_FILE"
|
||||
else
|
||||
sed -n -i.bkp '/'"$begin"'/,/'"$end"'/ {
|
||||
/'"$begin"'/n # skip over the line that has "$begin" on it
|
||||
/'"$end"'/ !{ # skip over the line that has "$end" on it
|
||||
s/*//
|
||||
r '"${theme}/config"'
|
||||
# TODO: add a line with only "include /nanorc/*"
|
||||
d
|
||||
}
|
||||
}' "$G_FILE"
|
||||
sed -n -i.bkp '$sed_no_lite' "$G_FILE"
|
||||
_update_nanorc
|
||||
fi
|
||||
}
|
||||
|
14
tests.sh
14
tests.sh
@ -42,30 +42,28 @@ f_compare_version(){
|
||||
|
||||
# Test Functions
|
||||
|
||||
f_test_nano_version() {
|
||||
f_test_nano_version(){
|
||||
local version
|
||||
version="$(nano --version | cut -d ' ' -f 5 | head -n 1)"
|
||||
echo $G_NANO_VERSION
|
||||
echo $version
|
||||
f_compare_version "$G_NANO_VERSION" "$version"
|
||||
return $?
|
||||
}
|
||||
|
||||
f_test_shellcheck_version() {
|
||||
f_test_shellcheck_version(){
|
||||
local version
|
||||
version="$(shellcheck --version | cut -d ' ' -f 2 | head -n 2 | tail -n 1)"
|
||||
echo $G_SHELLCHECK_VERSION
|
||||
echo $version
|
||||
f_compare_version "$G_SHELLCHECK_VERSION" "$version"
|
||||
return $?
|
||||
}
|
||||
|
||||
# MAIN TESTS
|
||||
|
||||
printf "=================\n"
|
||||
printf "TESTS\n"
|
||||
printf "=================\n"
|
||||
f_test_nano_version
|
||||
printf "Nano Version ok? %s (1 = ok)\n" "$?"
|
||||
printf "Nano Version ok? %s (0 = ok)\n" "$?"
|
||||
f_test_shellcheck_version
|
||||
printf "Shellcheck Version ok? %s (1 = ok)\n" "$?"
|
||||
printf "Shellcheck Version ok? %s (0 = ok)\n" "$?"
|
||||
# ....shellcheck -f diff *.sh | git apply | git commit -a -m "Shellcheck fast corrections"
|
||||
shellcheck -- *.sh
|
||||
|
Loading…
x
Reference in New Issue
Block a user