Skip to content
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

Allow registering internal hooks when variables are changed, e.g. LANG #527

Open
andychu opened this issue Nov 8, 2019 · 4 comments
Open

Comments

@andychu
Copy link
Contributor

andychu commented Nov 8, 2019

  • We need this for LANG=C support. See Test effect of locale environment variables on Oil #522
  • Use case: validation
    • HOME=(an array) should be a runtime error?
  • This would likely make some other things more efficient
  • IFS? PS1? I think those have cached parsed representations so it's OK.
@andychu andychu changed the title Allow registering internal hooks when variables are changed Allow registering internal hooks when variables are changed, e.g. LANG Nov 8, 2019
@andychu
Copy link
Contributor Author

andychu commented Nov 8, 2019

bash has a ton of these hooks in variables.c. We might only need a few

static struct name_and_function special_vars[] = {                                                                                                                                                                                            
  { "BASH_COMPAT", sv_shcompat },                                                                                                                                                                                                             
  { "BASH_XTRACEFD", sv_xtracefd },                                                                                                                                                                                                           
                                                                                                                                                                                                                                              
#if defined (JOB_CONTROL)                                                                                                                                                                                                                     
  { "CHILD_MAX", sv_childmax },                                                                                                                                                                                                               
#endif                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                              
#if defined (READLINE)                                                                                                                                                                                                                        
#  if defined (STRICT_POSIX)                                                                                                                                                                                                                  
  { "COLUMNS", sv_winsize },                                                                                                                                                                                                                  
#  endif                                                                                                                                                                                                                                      
  { "COMP_WORDBREAKS", sv_comp_wordbreaks },                                                                                                                                                                                                  
#endif                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                              
  { "EXECIGNORE", sv_execignore },                                                                                                                                                                                                            
                                                                                                                                                                                                                                              
  { "FUNCNEST", sv_funcnest },                                                                                                                                                                                                                
                                                                                                                                                                                                                                              
  { "GLOBIGNORE", sv_globignore },                                                                                                                                                                                                            
                                                                                                                                                                                                                                              
#if defined (HISTORY)                                                                                                                                                                                                                         
  { "HISTCONTROL", sv_history_control },                                                                                                                                                                                                      
  { "HISTFILESIZE", sv_histsize },                                                                                                                                                                                                            
  { "HISTIGNORE", sv_histignore },                                                                                                                                                                                                            
  { "HISTSIZE", sv_histsize },                                                                                                                                                                                                                
  { "HISTTIMEFORMAT", sv_histtimefmt },                                                                                                                                                                                                       
#endif                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                              
#if defined (__CYGWIN__)                                                                                                                                                                                                                      
  { "HOME", sv_home },                                                                                                                                                                                                                        
#endif                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                              
#if defined (READLINE)                                                                                                                                                                                                                        
  { "HOSTFILE", sv_hostfile },                                                                                                                                                                                                                
#endif                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                              
  { "IFS", sv_ifs },                                                                                                                                                                                                                          
  { "IGNOREEOF", sv_ignoreeof },                                                                                                                                                                                                              
                                                                                                                                                                                                                                              
  { "LANG", sv_locale },                                                                                                                                                                                                                      
  { "LC_ALL", sv_locale },                                                                                                                                                                                                                    
  { "LC_COLLATE", sv_locale },                                                                                                                                                                                                                
  { "LC_CTYPE", sv_locale },                                                                                                                                                                                                                  
  { "LC_MESSAGES", sv_locale },                                                                                                                                                                                                               
  { "LC_NUMERIC", sv_locale },                                                                                                                                                                                                                
  { "LC_TIME", sv_locale },                                                                                                                                                                                                                   
                                                                                                                                                                                                                                              
#if defined (READLINE) && defined (STRICT_POSIX)                                                                                                                                                                                              
  { "LINES", sv_winsize },                                                                                                                                                                                                                    
#endif                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                              
  { "MAIL", sv_mail },                                                                                                                                                                                                                        
  { "MAILCHECK", sv_mail },                                                                                                                                                                                                                   
  { "MAILPATH", sv_mail },                                                                                                                                                                                                                    
                                                                                                                                                                                                                                              
  { "OPTERR", sv_opterr },                                                                                                                                                                                                                    
  { "OPTIND", sv_optind },                                                                                                                                                                                                                    
                                                                                                                                                                                                                                              
  { "PATH", sv_path },                                                                                                                                                                                                                        
  { "POSIXLY_CORRECT", sv_strict_posix },                   

@andychu
Copy link
Contributor Author

andychu commented Jan 25, 2020

Note: dash has this. There's a function pointer in the variable binding structure that gets called upon mutation

@andychu
Copy link
Contributor Author

andychu commented Mar 21, 2020

  • note TZ seems like it should behave like this, but it doesn't!
    • putenv() could be there? But you might need an unset hook too!
    • but tzset() can't be there? Because then it would affect it when NOT exported.

@andychu
Copy link
Contributor Author

andychu commented May 15, 2021

Somewhat related to #682 -- a variable change could be a hook?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant