-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Clean themes A-L #2315
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
base: master
Are you sure you want to change the base?
Clean themes A-L #2315
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
90% there.
@@ -85,7 +86,7 @@ IP_SEPARATOR=', ' | |||
|
|||
function get_ip_info { | |||
myip=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+') | |||
echo -e "$(ips | sed -e :a -e '$!N;s/\n/${IP_SEPARATOR}/;ta' | sed -e 's/127\.0\.0\.1\${IP_SEPARATOR}//g'), ${myip}" | |||
echo -e "$(ips | sed -e :a -e "\$!N;s/\\n/${IP_SEPARATOR}/;ta" | sed -e "s/127\\.0\\.0\\.1\\${IP_SEPARATOR}//g"), ${myip}" | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch... did this even work before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it. But for both before and after my fix, when I tried to run it, I got really weird output (maybe my ips
executable is not the right one?). I left the possibility of further fixes for later,.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it worked before. Rather, this PR breaks the second sed
pattern.
In the original code, the first sed
expression converted the newlines to the literal ${IP_SEPARATOR}
, and the second sed
expression deleted the literal 127.0.0.1${IP_SEPARATOR}
. I guess the literal ${IP_SEPARATOR}
would finally be included in PS1
, and Bash expands it on the prompt evaluation.
However, after the present change, I'm afraid that there would be multiple problems:
- The first
sed
expression converts the newlines to the value of the shell variableIP_SEPARATOR
, but the secondsed
expression still tries to match the literal${IP_SEPARATOR}
instead of matching the value of the shell variableIP_SEPARATOR
. - When the user stores
/
or something to the shell variableIP_SEPARATOR
, the slash would be treated as the terminator of thesed
operators
, and it causes problems. If one would like to use the value ofIP_SEPARATOR
, one should properly quote the value ofIP_SEPARATOR
before embedding it in thesed
expression. - When the user stores strings looking like a prompt escape sequence or shell expansions, it would be expanded unexpectedly when
PS1
is evaluated. If one would like to expand the value ofIP_SEPARATOR
within this function, one should additionally quote the value so that the prompt evaluation ofPS1
would reproduce the value ofIP_SEPARATOR
literally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edwin, care to fix the last bits so we can sign up on the merge?
@@ -170,7 +174,7 @@ function limited_pwd() { | |||
# Replace $HOME with ~ if possible | |||
RELATIVE_PWD=${PWD/#$HOME/\~} | |||
|
|||
local offset=$((${#RELATIVE_PWD} - $MAX_PWD_LENGTH)) | |||
local offset=$((${#RELATIVE_PWD} - MAX_PWD_LENGTH)) | |||
|
|||
if [ $offset -gt "0" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why the shellcheck doesn't complain about this unquoted $offset
. Maybe it is because IFS
is not modified inside this file and offset
is ensured to contain a number in this context? However, the shell configuration should anticipate an arbitrary IFS
value set outside the file by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that recent ShellCheck releases have become better at knowing when variables have a value that can only be a number. But I disagree that it should anticipate an arbitrary IFS
value - the value deduction is just too handy and it covers 99% of setups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I disagree that it should anticipate an arbitrary
IFS
value - the value deduction is just too handy and it covers 99% of setups.
I wouldn't argue that there would be a sane setup with IFS
including numbers, but it is a valid usage to temporarily set IFS
to a number, do something, and then revert it.
$ oldifs=${IFS-$' \t\n'}
$ IFS='blahblah'
$ do-something
$ IFS=$oldifs
In such a case, [ $offset -gt "0" ]
may be broken temporarily for the third and fourth prompts.
Actually, one could simply rewrite it as ((offset > 0))
, which is more obvious and easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I disagree that it should anticipate an arbitrary
IFS
value - the value deduction is just too handy and it covers 99% of setups.
I was actually a bit confused about the point, but have you possibly misunderstood as if I thought ShellCheck should anticipate an arbitrary IFS
? No, I don't think ShellCheck should anticipate an arbitrary IFS
value. It is understandable that ShellCheck assumes the normal IFS
when the script does not modify IFS
. By the shell configuration in my original reply, I meant Bash-it (which is a configuration for interactive shell sessions), but I didn't mean ShellCheck. The situation with interactive shell settings are a bit different from that for normal shell scripts. The user has access to all the global variables, and the user may modify these at arbitrary time based on what the user wants to do. An interactive shell configuration should care about various possibilities for the commonly used variables, such as IFS
.
Description
As per #1696, this cleans up various files by fixing ShellCheck errors.
This cleans 10 themes (and removes two entries from
clean_files.txt
that no longer exist.In the agnoster theme, I changed the "Git repository dirty check" to be more consistent with what I added in hawaii50 (to fix a ShellCheck issue).
Motivation and Context
As mentioned in #1696, this minimizes mistakes in the code.
How Has This Been Tested?
Ran
./lint_clean_files.sh
successfully.Screenshots (if appropriate):
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.