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_FILE="${HOME}/.nanorc"
|
||||||
G_REPO_MASTER="https://github.com/scopatz/nanorc/archive/master.zip"
|
G_REPO_MASTER="https://github.com/scopatz/nanorc/archive/master.zip"
|
||||||
G_REPO_RELEASE="https://github.com/scopatz/nanorc/archive/${G_VERSION}.zip"
|
G_REPO_RELEASE="https://github.com/scopatz/nanorc/archive/${G_VERSION}.zip"
|
||||||
G_NANO_VERSION="4.6.0"
|
# G_NANO_VERSION="4.6.0"
|
||||||
G_NANO_NRC_DIR=""
|
# G_NANO_NRC_DIR=""
|
||||||
unset G_LITE G_UNSTABLE G_VERBOSE G_DIR G_THEME
|
unset G_LITE G_UNSTABLE G_VERBOSE G_DIR G_THEME
|
||||||
|
|
||||||
# Exit Values Help
|
# Exit Values Help
|
||||||
@ -175,6 +175,9 @@ f_install(){
|
|||||||
begin="# BEGIN"
|
begin="# BEGIN"
|
||||||
end="# END"
|
end="# END"
|
||||||
theme="${G_DIR}/themes/${G_THEME}/"
|
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
|
if cd "$HOME"; then
|
||||||
printf "\n Error: Cannot open or access '%s' directory." "${HOME}"
|
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"
|
printf "\n %s \n %s \n" "$begin" "$end" >> "$G_FILE"
|
||||||
|
|
||||||
if [ "$G_LITE" = true ]; then
|
if [ "$G_LITE" = true ]; then
|
||||||
sed -n -i.bkp '/'"$begin"'/,/'"$end"'/ {
|
sed -n -i.bkp '$sed_lite' "$G_FILE"
|
||||||
/'"$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"
|
|
||||||
else
|
else
|
||||||
sed -n -i.bkp '/'"$begin"'/,/'"$end"'/ {
|
sed -n -i.bkp '$sed_no_lite' "$G_FILE"
|
||||||
/'"$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"
|
|
||||||
_update_nanorc
|
_update_nanorc
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
10
tests.sh
10
tests.sh
@ -45,8 +45,6 @@ f_compare_version(){
|
|||||||
f_test_nano_version(){
|
f_test_nano_version(){
|
||||||
local version
|
local version
|
||||||
version="$(nano --version | cut -d ' ' -f 5 | head -n 1)"
|
version="$(nano --version | cut -d ' ' -f 5 | head -n 1)"
|
||||||
echo $G_NANO_VERSION
|
|
||||||
echo $version
|
|
||||||
f_compare_version "$G_NANO_VERSION" "$version"
|
f_compare_version "$G_NANO_VERSION" "$version"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
@ -54,18 +52,18 @@ f_test_nano_version() {
|
|||||||
f_test_shellcheck_version(){
|
f_test_shellcheck_version(){
|
||||||
local version
|
local version
|
||||||
version="$(shellcheck --version | cut -d ' ' -f 2 | head -n 2 | tail -n 1)"
|
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"
|
f_compare_version "$G_SHELLCHECK_VERSION" "$version"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# MAIN TESTS
|
||||||
|
|
||||||
printf "=================\n"
|
printf "=================\n"
|
||||||
printf "TESTS\n"
|
printf "TESTS\n"
|
||||||
printf "=================\n"
|
printf "=================\n"
|
||||||
f_test_nano_version
|
f_test_nano_version
|
||||||
printf "Nano Version ok? %s (1 = ok)\n" "$?"
|
printf "Nano Version ok? %s (0 = ok)\n" "$?"
|
||||||
f_test_shellcheck_version
|
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 -f diff *.sh | git apply | git commit -a -m "Shellcheck fast corrections"
|
||||||
shellcheck -- *.sh
|
shellcheck -- *.sh
|
||||||
|
Loading…
x
Reference in New Issue
Block a user