Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ii:labs:01:tasks:03 [2021/10/09 21:54]
radu.mantu [03. [20p] Quality-of-life improvements]
ii:labs:01:tasks:03 [2024/10/18 12:35] (current)
radu.mantu [03. [20p] Quality-of-life improvements]
Line 26: Line 26:
 </​code>​ </​code>​
  
 +<note important>​
 +If the command above doesn'​t work, it's possible that **echo** doesn'​t interpret escape sequences.
 +
 +Either add the **-e** argument to //enable interpretation of backslash escapes//, or replace **echo** with **printf** and add a ''​\n''​.
 +</​note>​
  
 We can use this... Add this at the end of your //.zshrc// file, source it, and open the same man page again: We can use this... Add this at the end of your //.zshrc// file, source it, and open the same man page again:
Line 46: Line 51:
   * ''​man()'':​ we're basically replacing the **man** command with a //bash function//.   * ''​man()'':​ we're basically replacing the **man** command with a //bash function//.
   * ''​LESS_TERMCAP_*'':​ these are variables used (indirectly) by **man** to format its output. The authors of these pages decide how and when to use them. We decide what they are. By defining these variables before running a bash command, we set them only in the environment of the started process and will disappear when said process terminates.   * ''​LESS_TERMCAP_*'':​ these are variables used (indirectly) by **man** to format its output. The authors of these pages decide how and when to use them. We decide what they are. By defining these variables before running a bash command, we set them only in the environment of the started process and will disappear when said process terminates.
-  * ''​command man "​$@"'':​ here, **command** tells **bash** / **zsh** to use the //​original//​ man command, not the function we just defined. If you're wandering why this is necessary, think back to the whole ''​tmux''​ and ''​zsh''​ fiasco described earlier. The ''"​%@"''​ here is substituted with all the arguments that the //**man** bash function// received and passes them on to the //**man** command//.+  * ''​command man "​$@"'':​ here, **command** tells **bash** / **zsh** to use the //​original//​ man command, not the function we just defined. If you're wandering why this is necessary, think back to the whole ''​tmux''​ and ''​zsh''​ fiasco described earlier. The ''"​$@"''​ here is substituted with all the arguments that the //**man** bash function// received and passes them on to the //**man** command//. 
 + 
 +**//​Alternatively//​** you can change the [[https://​unix.stackexchange.com/​questions/​144016/​what-is-a-pager|pager]] used by **man** from **less** to **[n]vim**. This means that every time you bring up the manual page for something, it will be opened in your favorite text editor. 
 + 
 +First of all, let's install **nvim**. This is a //fork// of **vim** created due to Bram Moolenaar (the author of **vim**) rejecting a large number of improvements proposed by the community. 
 + 
 +<code bash> 
 +$ sudo apt install neovim 
 +</​code>​ 
 + 
 +To change **man**'​s pager from **less** to **nvim**, add the following line to your ''​.zshrc''​ and source it. 
 + 
 +<​code>​ 
 +export MANPAGER='​nvim +Man!'​ 
 +</​code>​ 
 + 
 +Now, try opening a manual page: 
 + 
 +<code bash> 
 +$ man 2 open 
 +</​code>​
  
 === [10p] Task B - Color iproute2 output === === [10p] Task B - Color iproute2 output ===
Line 54: Line 79:
 <code bash> <code bash>
 # alias for iproute2 color output # alias for iproute2 color output
-ip='ip -c'+alias ip='ip -c'
 </​code>​ </​code>​
  
 Source //.zshrc// and try ''​ip addr show''​ again. Now, every time you run ''​ip'',​ it automatically expands to ''​ip -c''​. Source //.zshrc// and try ''​ip addr show''​ again. Now, every time you run ''​ip'',​ it automatically expands to ''​ip -c''​.
ii/labs/01/tasks/03.1633805655.txt.gz · Last modified: 2021/10/09 21:54 by radu.mantu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0