Tag: configuration

  • Nano: The One True Editor

    Nano: The One True Editor

    Forget about vi/vim/edlin. Nano is the only editor that you need in the console. Sure, it may not be perfect, but with a few extra steps in .nanorc it can really be a great experience. Here’s my .nanorc with some comments showing what’s changed:

    ## Automatically indent a newly created line to the same number of tabs and/or spaces as the previous line (or as the next line if the previous line is the beginning of a paragraph).
    unset autoindent
    
    ## Use bold instead of reverse video
    set boldtext
    
    ## Save the last hundred search strings and replacement strings and executed commands, so they can be easily reused in later sessions.
    set historylog
    
    ## Display line numbers to the left of the text area.
    set linenumbers
    
    ## Enable mouse support, if available for your system. When enabled, mouse clicks can be used to place the cursor, set the mark (with a double click), and execute shortcuts. The mouse will work in the X Window System, and on the console when gpm is running. Text can still be selected through dragging by holding down the Shift key.
    set mouse
    
    ## Save the cursor position of files between editing sessions. The cursor position is remembered for the 200 most-recently edited files.
    set positionlog
    
    ## Use a tab size of number columns. The value of number must be greater than 0. The default value is 8.
    set tabsize 4
    
    ## Default Syntax Highlighting
    include "/usr/share/nano/asm.nanorc"
    include "/usr/share/nano/autoconf.nanorc"
    include "/usr/share/nano/awk.nanorc"
    include "/usr/share/nano/c.nanorc"
    include "/usr/share/nano/changelog.nanorc"
    include "/usr/share/nano/cmake.nanorc"
    include "/usr/share/nano/css.nanorc"
    include "/usr/share/nano/debian.nanorc"
    include "/usr/share/nano/default.nanorc"
    include "/usr/share/nano/elisp.nanorc"
    include "/usr/share/nano/fortran.nanorc"
    include "/usr/share/nano/gentoo.nanorc"
    include "/usr/share/nano/go.nanorc"
    include "/usr/share/nano/groff.nanorc"
    include "/usr/share/nano/guile.nanorc"
    include "/usr/share/nano/html.nanorc"
    include "/usr/share/nano/java.nanorc"
    include "/usr/share/nano/javascript.nanorc"
    include "/usr/share/nano/json.nanorc"
    include "/usr/share/nano/lua.nanorc"
    include "/usr/share/nano/makefile.nanorc"
    include "/usr/share/nano/man.nanorc"
    include "/usr/share/nano/mgp.nanorc"
    include "/usr/share/nano/mutt.nanorc"
    include "/usr/share/nano/nanorc.nanorc"
    include "/usr/share/nano/nftables.nanorc"
    include "/usr/share/nano/objc.nanorc"
    include "/usr/share/nano/ocaml.nanorc"
    include "/usr/share/nano/patch.nanorc"
    include "/usr/share/nano/perl.nanorc"
    include "/usr/share/nano/php.nanorc"
    include "/usr/share/nano/po.nanorc"
    include "/usr/share/nano/postgresql.nanorc"
    include "/usr/share/nano/pov.nanorc"
    include "/usr/share/nano/python.nanorc"
    include "/usr/share/nano/ruby.nanorc"
    include "/usr/share/nano/rust.nanorc"
    include "/usr/share/nano/sh.nanorc"
    include "/usr/share/nano/spec.nanorc"
    include "/usr/share/nano/tcl.nanorc"
    include "/usr/share/nano/tex.nanorc"
    include "/usr/share/nano/texinfo.nanorc"
    include "/usr/share/nano/xml.nanorc"Code language: PHP (php)

  • Auto-enable WP_DEBUG with a cookie

    Auto-enable WP_DEBUG with a cookie

    One of the most important things to do when working on new themes, plugins, or debugging issues in WordPress is to turn on WP_DEBUG.  According to the Codex:

    WP_DEBUG is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. It is assumed to be false by default and is usually set to true in the wp-config.php file on development copies of WordPress.

    It’s common to edit the wp-config.php file every time you want to turn this off and on, but another way to do it is via a secret cookie:

    if ( isset( $_COOKIE[ 'wp_secret_debug_cookie' ] ) ) {
    	define( 'WP_DEBUG', true );
    }Code language: PHP (php)

    I also like to pair my WP_DEBUG with these extra settings:

    if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
    	define( 'WP_DEBUG_LOG', true );
    	define( 'SCRIPT_DEBUG', true );
    	define( 'WP_DEBUG_DISPLAY', true );
    	define( 'CONCATENATE_SCRIPTS', false );
    	define( 'SAVEQUERIES', true );
    }Code language: JavaScript (javascript)

    I set the cookie in an mu-plugin like this (Note: This code could definitely be improved)

    function emrikol_admin_debug() {
    	if ( is_super_admin() ) {
    		setcookie( 'wp_secret_debug_cookie', 'on', time() + 86400, '/', wp_parse_url( get_site_url(), PHP_URL_HOST ) );
    		setcookie( 'wp_secret_debug_cookie', 'on', time() + 86400, '/', wp_parse_url( get_home_url(), PHP_URL_HOST ) );
    		setcookie( 'wp_secret_debug_cookie', 'on', time() + 86400, '/', wp_parse_url( get_admin_url(), PHP_URL_HOST ) );
    
    		// Allow sites to set extra domains to add cookie to--good for subdomain multisite.
    		$extra_domains = apply_filters( 'emrikol_admin_debug_domain', false );
    		if ( false !== $extra_domains ) {
    			if ( is_array( $extra_domains ) ) {
    				foreach ( $extra_domains as $extra_domain ) {
    					setcookie( 'wp_secret_debug_cookie', 'on', time() + 86400, '/', $extra_domain );
    				}
    			} else {
    					setcookie( 'wp_secret_debug_cookie', 'on', time() + 86400, '/', $extra_domains );
    			}
    		}
    	}
    }
    add_action( 'init', 'emrikol_admin_debug', 10 );
    add_action( 'admin_init', 'emrikol_admin_debug', 10 );Code language: PHP (php)