<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>unix Archives - Tom Barbette</title>
	<atom:link href="https://perso.uclouvain.be/tom.barbette/tag/unix-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://perso.uclouvain.be/tom.barbette/tag/unix-2/</link>
	<description></description>
	<lastBuildDate>Thu, 05 Feb 2015 13:52:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://perso.uclouvain.be/tom.barbette/wp-content/uploads/2022/04/cropped-logo-uclouvain-2021-barbette-32x32.png</url>
	<title>unix Archives - Tom Barbette</title>
	<link>https://perso.uclouvain.be/tom.barbette/tag/unix-2/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Home server : auto-shutdown if no other computers are running</title>
		<link>https://perso.uclouvain.be/tom.barbette/home-server-shutdown-computer-if-no-other-computers-are-up-on-the-network/</link>
		
		<dc:creator><![CDATA[Tom Barbette]]></dc:creator>
		<pubDate>Mon, 31 Mar 2014 23:49:53 +0000</pubDate>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Server management]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[shutdown]]></category>
		<category><![CDATA[unix]]></category>
		<guid isPermaLink="false">http://queen.run.montefiore.ulg.ac.be/~barbette/?p=273</guid>

					<description><![CDATA[<p>I wanted to shutdown my linux home media server if there is no running computer on my network. So I wrote this little programs which reads all known ips from DHCP configuration and lease files and send a ping to them. If the ping respond, one PC of my LAN is up&#8230; To re-start the &#8230; </p>
<p class="link-more"><a href="https://perso.uclouvain.be/tom.barbette/home-server-shutdown-computer-if-no-other-computers-are-up-on-the-network/" class="more-link">Continue reading<span class="screen-reader-text"> "Home server : auto-shutdown if no other computers are running"</span></a></p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/home-server-shutdown-computer-if-no-other-computers-are-up-on-the-network/">Home server : auto-shutdown if no other computers are running</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I wanted to shutdown my linux home media server if there is no running computer on my network. So I wrote this little programs which reads all known ips from DHCP configuration and lease files and send a ping to them. If the ping respond, one PC of my LAN is up&#8230;</p>
<p>To re-start the computer in the morning, I use the BIOS RTC alarm (the thing you have by pressing F1 or ESC on reboot). You could also add a script/a program on each of your computers to send the magic packet to your home server to wake it by lan (see &#8220;wake on lan&#8221; on google).</p>
<p>This script can take any command. But if you want to do shutdown like proposed in the title, you can use :</p>
<p>[code]sudo ./autoshut &#8220;poweroff&#8221; 10.0.0.1[/code]</p>
<p>Where 10.0.0.1 is your local IP adress. To compile the program, simply use (after saving the code as &#8220;autoshut.c&#8221;) : [code]gcc -o autoshut autoshut.c[/code]</p>
<p>In my case, I wanted to launch the command only after midnight, so I used cron. Cron will launch that command every 5 minutes from midnight to eight o&#8217;clock. So if I stay up late, my server won&#8217;t shutdown if my own computer is not down too. That&#8217;s the whole purpose.</p>
<p>The line in my crontab :</p>
<p>[code]0,10,20,30,40,50 1,2,3,4,5,6,7 * * * root /home/tom/autoshut/autoshut &#8220;poweroff&#8221; 10.0.0.1[/code]</p>
<p>Why do all that ? Energy consumption&#8230;</p>
<p>[code]#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;regex.h&gt;<br />
#include &lt;string.h&gt;</p>
<p>#define LEASE_FILE &#8220;/var/lib/dhcp/dhcpd.leases&#8221;<br />
#define DHCP_CONFIG_FILE &#8220;/etc/dhcp/dhcpd.conf&#8221;</p>
<p>int in_array(char** ar, char* str) {<br />
int i = 0;<br />
while (ar[i] != NULL) {<br />
if (strcmp(ar[i],str) == 0) return 1;<br />
i++;<br />
}<br />
return 0;<br />
}</p>
<p>char* extractIP (char* filename, char** list, int* listNum) {<br />
FILE *pfile;</p>
<p>pfile = fopen(filename, &#8220;rb&#8221;);</p>
<p>if(pfile == NULL){<br />
printf(&#8220;Sorry, can&#8217;t open %s\n&#8221;, filename);<br />
return &#8216;\0&#8217;;<br />
}<br />
regex_t reg;<br />
int err = regcomp (&amp;reg, &#8220;(10\\.[0-1]\\.0\\.([1-9]|[0-9]{2,3}))&#8221;, REG_EXTENDED);<br />
if (err != 0)<br />
{<br />
printf(&#8220;ERREUR\n&#8221;);<br />
return &#8216;\0&#8217;;<br />
}<br />
char ligne[255];</p>
<p>while(!feof(pfile)) {<br />
fgets(ligne, 254 ,pfile);<br />
int match;<br />
size_t nmatch = 0;<br />
regmatch_t *pmatch = NULL;</p>
<p>nmatch = reg.re_nsub;<br />
pmatch = malloc (sizeof (*pmatch) * nmatch);<br />
match = regexec (&amp;reg, ligne, nmatch, pmatch, 0);<br />
if (match == 0)<br />
{<br />
char *ip = NULL;<br />
int start = pmatch-&gt;rm_so;<br />
int end = pmatch-&gt;rm_eo;<br />
size_t size = end &#8211; start;</p>
<p>char* str = malloc(sizeof(char) * 15);<br />
strncpy (str, &amp;ligne[start], size);<br />
str[size] = &#8216;\0&#8217;;</p>
<p>if (!in_array(list, str)) {<br />
list[*listNum] = str;<br />
printf(&#8220;%s\n&#8221;, str);<br />
(*listNum)++;<br />
}</p>
<p>}</p>
<p>}</p>
<p>fclose(pfile);<br />
regfree(&amp;reg);<br />
}</p>
<p>int ping(char* address) {</p>
<p>char cmd[30] = &#8220;ping -W 1 -q -c 1 &#8220;;<br />
strcat(cmd,address);<br />
int ret=system(cmd);<br />
printf(&#8220;\nResultat : %d\n\n&#8221;,ret);<br />
return !ret;<br />
}<br />
/*<br />
TODO : maybe an option?<br />
int checkCableStatus(const char* interface) {<br />
/sys/class/net/eth0/carrier<br />
}*/</p>
<p>int main(int argc, char** argv) {</p>
<p>if (argc &lt;= 2) {<br />
printf(&#8220;Usage : %s Command Local-IP [Local-IP-2]\n\tCommand : a command to execute if ping does not work\n\tLocal-IP : Ip to ignore\n\tLocal-IP-2 : Optional second ip to ignore&#8221;,argv[0]);<br />
return -1;<br />
}<br />
int listNum = 0;<br />
char** list = malloc(sizeof(char*) * 255);<br />
extractIP(DHCP_CONFIG_FILE, list, &amp;listNum);<br />
extractIP(LEASE_FILE, list, &amp;listNum);<br />
int i = 0;<br />
while (list[i] != NULL) {<br />
if (strcmp(list[i],argv[2])!=0 &amp;&amp; (argc==3 ||strcmp(list[i],argv[3])!=0)) {<br />
if (ping (list[i])) {<br />
printf(&#8220;%s responded. Command aborted !\n&#8221;,list[i]);<br />
return EXIT_SUCCESS;<br />
}<br />
}<br />
i++;<br />
}<br />
system(argv[1]);<br />
return EXIT_SUCCESS;<br />
}[/code]</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/home-server-shutdown-computer-if-no-other-computers-are-up-on-the-network/">Home server : auto-shutdown if no other computers are running</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ugly things : do not ask password for sudo</title>
		<link>https://perso.uclouvain.be/tom.barbette/ugly-things-do-not-ask-password-for-sudo/</link>
		
		<dc:creator><![CDATA[Tom Barbette]]></dc:creator>
		<pubDate>Mon, 03 Feb 2014 10:53:37 +0000</pubDate>
				<category><![CDATA[INFO-0940 Operating Systems]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[info0940]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[ugly]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[visudo]]></category>
		<guid isPermaLink="false">http://queen.run.montefiore.ulg.ac.be/~barbette/?p=155</guid>

					<description><![CDATA[<p>&#8211;> Ugly but okay in a development virtual machine Launch the command &#8220;sudo visudo&#8221; in a terminal. Add at the end : student ALL=(ALL) NOPASSWD: ALL And student will have no password prompt when using sudo</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/ugly-things-do-not-ask-password-for-sudo/">Ugly things : do not ask password for sudo</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>&#8211;> Ugly but okay in a development virtual machine</p>
<p>Launch the command &#8220;sudo visudo&#8221; in a terminal.</p>
<p>Add at the end :<br />
<code sh>student ALL=(ALL) NOPASSWD: ALL</code></p>
<p>And student will have no password prompt when using sudo</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/ugly-things-do-not-ask-password-for-sudo/">Ugly things : do not ask password for sudo</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ugly things : Autologin of console at startup</title>
		<link>https://perso.uclouvain.be/tom.barbette/ugly-things-autologin-of-console-at-startup/</link>
		
		<dc:creator><![CDATA[Tom Barbette]]></dc:creator>
		<pubDate>Mon, 03 Feb 2014 10:51:47 +0000</pubDate>
				<category><![CDATA[INFO-0940 Operating Systems]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[info0940]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ugly]]></category>
		<category><![CDATA[unix]]></category>
		<guid isPermaLink="false">http://queen.run.montefiore.ulg.ac.be/~barbette/?p=153</guid>

					<description><![CDATA[<p>→ Ugly but okay in a development virtual machine… Add &#8220;– – autologin root&#8221; at the end of /etc/init/tty1.conf It will auto-log you as root for the first console. For the others, do the same with /etc/init/tty[1-5].conf You can autolog as “student” by replacing root by student. It’s a little safer … but still ugly.</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/ugly-things-autologin-of-console-at-startup/">Ugly things : Autologin of console at startup</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>→ Ugly but okay in a development virtual machine…</p>
<p>Add &#8220;– – autologin <strong>root</strong>&#8221; at the end of /etc/init/tty1.conf</p>
<p>It will auto-log you as root for the first console. For the others, do the same with /etc/init/tty[1-5].conf</p>
<p>You can autolog as “student” by replacing <strong>root</strong> by student. It’s a little safer … but still ugly.</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/ugly-things-autologin-of-console-at-startup/">Ugly things : Autologin of console at startup</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Detecting if another user is connected on UNIX systems</title>
		<link>https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/</link>
		
		<dc:creator><![CDATA[Tom Barbette]]></dc:creator>
		<pubDate>Tue, 14 Jan 2014 10:11:06 +0000</pubDate>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[connected]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[users]]></category>
		<guid isPermaLink="false">http://queen.run.montefiore.ulg.ac.be/~barbette/?p=76</guid>

					<description><![CDATA[<p>How to detect if another user is connected to your machine or your server? You can use the command &#8220;users&#8221; to check yourself is someone is connected. But to do it automatically, you&#8217;ll have to use some pipe : [code lang=&#8221;bash&#8221;]expr length &#8220;`users &#124; sed -e &#8220;s/\($USER\&#124;\[ \]*\)//ig&#8221;`&#8221;[/code] The first thing executed by the shell &#8230; </p>
<p class="link-more"><a href="https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/" class="more-link">Continue reading<span class="screen-reader-text"> "Detecting if another user is connected on UNIX systems"</span></a></p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/">Detecting if another user is connected on UNIX systems</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>How to detect if another user is connected to your machine or your server? You can use the command &#8220;users&#8221; to check yourself is someone is connected. But to do it automatically, you&#8217;ll have to use some pipe :</p>
<p>[code lang=&#8221;bash&#8221;]expr length &#8220;`users | sed -e &#8220;s/\($USER\|\[ \]*\)//ig&#8221;`&#8221;[/code]</p>
<p>The first thing executed by the shell will be the thing under french apostrophe ( ` ). Theses are for evaluation a command, and replace it by what it outputs (normally print on the screen). The command users print the list of connected users into a pipe, to sed which evaluate its command as a regular expression (-e parameter). The command is &#8220;s&#8221; for substitute, and the rest tells him to find &#8220;$USER&#8221; (replaced by the currently connected user, you) and spaces and replace them by &#8230; nothing. So this part will be an empty string if there is no other users connected than &#8220;$USER&#8221; and something not empty if there is.</p>
<p>The &#8220;expr length&#8221; return the length of a string. So this commands print 0 if there is no other user connected, and &gt;0 if there is some !</p>
<p>In a shell script to do something if yes or no&#8230;<br />
[code lang=&#8221;bash&#8221;]#!/bin/sh<br />
usersstripped=`users | sed -e &#8220;s/\(<strong>tom</strong>\|\[ \]*\)//ig&#8221;`<br />
connected=`expr length &#8220;$usersstripped&#8221;`<br />
if [ &#8220;$connected&#8221; -eq &#8220;0&#8221; ] ; then<br />
echo &#8220;No other user is connected&#8221;<br />
else<br />
echo &#8220;Other user connected !&#8221;<br />
fi[/code]</p>
<p>It is essentially the same command but done in two times, as in a shell script this command would not be evaluated correctly.</p>
<p>And if you want to put that in a cron to eg. send you a mail, you just have to type &#8220;crontab -e&#8221; and put a line like :</p>
<p>[code]* * * * * /home/tom/connected[/code]</p>
<p>To launch it every minutes. But if you do that you&#8217;d better do something like detecting a connection&#8230;</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/">Detecting if another user is connected on UNIX systems</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>My .ZSHRC</title>
		<link>https://perso.uclouvain.be/tom.barbette/my-zshrc/</link>
		
		<dc:creator><![CDATA[Tom Barbette]]></dc:creator>
		<pubDate>Sun, 05 Jan 2014 16:33:37 +0000</pubDate>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[zsh]]></category>
		<category><![CDATA[zshrc]]></category>
		<guid isPermaLink="false">http://queen.run.montefiore.ulg.ac.be/~barbette/?p=65</guid>

					<description><![CDATA[<p>To gain a lot of time, you can replace the old &#8220;bash&#8221; by &#8220;zsh&#8221;, which is a very more powerful shell with autocompletion, but not only&#8230; It has a configuration file called &#8220;.zshrc&#8221; that you have to put in your home. You can try zsh by installing it and typing &#8220;zsh&#8221;, and if you&#8217;re convinced, &#8230; </p>
<p class="link-more"><a href="https://perso.uclouvain.be/tom.barbette/my-zshrc/" class="more-link">Continue reading<span class="screen-reader-text"> "My .ZSHRC"</span></a></p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/my-zshrc/">My .ZSHRC</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>To gain a lot of time, you can replace the old &#8220;bash&#8221; by &#8220;zsh&#8221;, which is a very more powerful shell with autocompletion, but not only&#8230; It has a configuration file called &#8220;.zshrc&#8221; that you have to put in your home. You can try zsh by installing it and typing &#8220;zsh&#8221;, and if you&#8217;re convinced, keeping it by typing chsh and choosing /bin/zsh.</p>
<p><span style="line-height: 1.5;">You have my entire .zshrc but I choose 3 snippets that I prefer to show you the usefullness :</span></p>
<p><span style="line-height: 1.5;">As I use Fedora, Debian, and Ubuntu, I made this to type &#8220;i program&#8221; to install profram on any system, and &#8220;u&#8221; to update the system. </span></p>
<p><span style="line-height: 1.5;"><br />
</span><span style="line-height: 1.5;">[code lang=&#8221;bash&#8221;]<br />
</span>#i for install, u for update</p>
<p>if [ -e /bin/yum ]; then<br />
alias i=&#8221;sudo yum install&#8221;<br />
alias u=&#8221;sudo yum update&#8221;<br />
else<br />
alias i=&#8221;sudo apt-get install&#8221;<br />
alias u=&#8221;sudo apt-get update &amp;&amp; sudo apt-get dist-upgrade&#8221;<br />
fi<br />
[/code]</p>
<p><span style="line-height: 1.5;">Force sudo for commands that anyway need it<br />
[code lang=&#8221;bash&#8221;]<br />
</span>alias yum=&#8221;sudo yum&#8221;<br />
alias apt-get=&#8221;sudo apt-get&#8221;<br />
alias service=&#8221;sudo service&#8221;<br />
[/code]</p>
<p>&nbsp;</p>
<p>Setting vi as default editor :<br />
[code lang=&#8221;bash&#8221;]<br />
export EDITOR=&#8221;vi&#8221;<br />
[/code]</p>
<p>&nbsp;</p>
<p>The multiples ssh shorcuts<br />
[code lang=&#8221;bash&#8221;]alias sshd=&#8221;ssh mappam.dyndns.org -X&#8221;<br />
alias sshc=&#8221;ssh itstudents.be -X -L 3129:localhost:3129&#8243;[/code]</p>
<p>I use my zshrc on multiple system and multiple environment, hence you have some tricks and multiplications like different variables for the same program in the path variable.</p>
<p>[code lang=&#8221;bash&#8221;]</p>
<p>#Using color schemes<br />
autoload -U colors &amp;&amp; colors</p>
<p>#Adding ADB to path variable<br />
export PATH=${PATH}:/usr/src/android-sdk-linux/platform-tools/:/usr/src/android-sdk-linux/tools/:/opt/android/platform-tols/</p>
<p>##################<br />
# Aliases<br />
##################<br />
#SSH shorcuts<br />
alias sshd=&#8221;ssh mappam.dyndns.org -X&#8221;<br />
alias sshc=&#8221;ssh itstudents.be -X -L 3129:localhost:3129&#8243;<br />
alias ssha=&#8221;ssh asbss.be -X&#8221;<br />
alias sshu=&#8221;ssh barbette@ms806.montefiore.ulg.ac.be -X&#8221;<br />
alias sshq=&#8221;ssh barbette@queen.run.montefiore.ulg.ac.be -X&#8221;<br />
alias scpi=&#8221;scp -i /home/tom/.ssh/id_rsa&#8221;<br />
alias scp3=&#8221;scp -P 3690 -i /home/tom/.ssh/id_rsa&#8221;<br />
alias sam=&#8221;ssh-add /home/tom/.ssh/id_rsa.montefiore&#8221;</p>
<p>#I have all my usefull scripts on my server itstudents, this alias update all scripts on a client, including this .zshrc<br />
alias us=&#8221;mkdir -p /home/tom/.scripts &amp;&amp; scpi tom@itstudents.be:/home/tom/.ssh/authorized_keys /home/tom/.ssh/authorized_keys &amp;&amp; scpi tom@itstudents.be:/home/tom/.zshrc /home/tom/.zshrc &amp;&amp; scpi -r tom@itstudents.be:/home/tom/.scripts/ /home/tom/ &amp;&amp; source /home/tom/.zshrc&#8221;</p>
<p>#Alias for these scripts&#8230;<br />
#Archiver pack a folder in tar.gz<br />
alias archiver=&#8221;/home/tom/.scripts/archiver&#8221;<br />
#Archiver7 pack a folder in a tar.7z<br />
alias archiver7=&#8221;/home/tom/.scripts/archiver7&#8243;<br />
#Update and reset permissions of an svn<br />
alias svnup=&#8221;/home/tom/.scripts/svnup&#8221;<br />
#Push an rsa key to the list of authorized keys<br />
alias pushrsa=&#8221;ssh tom@itstudents.be \&#8221;cat &#8211; &gt;&gt; /home/tom/.ssh/authorized_keys\&#8221; &lt; &#8221;</p>
<p>#Mount some local shares<br />
alias mh=&#8221;sudo mount -t nfs debserver:/home/tom /mnt/debserver-home&#8221;<br />
alias mp=&#8221;sudo mount -t nfs debserver:/pub /mnt/debserver-pub&#8221;</p>
<p>#Force sudo for some sudo-only commands like installers<br />
alias yum=&#8221;sudo yum&#8221;<br />
alias apt-get=&#8221;sudo apt-get&#8221;<br />
alias service=&#8221;sudo service&#8221;</p>
<p>#Some copy-pasted shorcut from elsewhere<br />
alias k=&#8217;tree&#8217;<br />
alias ltr=&#8217;ls -ltr&#8217;<br />
alias r=&#8217;screen -D -R&#8217;<br />
alias ls=&#8217;ls &#8211;color&#8217;<br />
alias l=&#8217;ls -lh&#8217;<br />
alias ll=&#8217;ls -la&#8217;<br />
#i for install, u for update<br />
if [ -e /bin/yum ]; then<br />
alias i=&#8221;sudo yum install&#8221;<br />
alias u=&#8221;sudo yum update&#8221;<br />
else<br />
alias i=&#8221;sudo apt-get install&#8221;<br />
alias u=&#8221;sudo apt-get update &amp;&amp; sudo apt-get dist-upgrade&#8221;<br />
fi</p>
<p>#Some links to launch programs on my android devices<br />
alias adbf=&#8221;ard &amp;&amp; adb forward tcp:8999 tcp:8999 &amp;&amp; google-chrome http://localhost:8999 &amp;&#8221;<br />
alias agmail=&#8221;adb shell am start -a android.intent.action.MAIN -n com.google.android.gm/.ConversationListActivityGmail&#8221;<br />
alias amail=&#8221;adb shell am start -a android.intent.action.MAIN -n com.google.android.email/com.android.email.activity.EmailActivity&#8221;<br />
alias ard=&#8221;adb shell am start -a android.intent.action.MAIN -n net.xdevelop.rm/.RemoteMobile&#8221;<br />
alias rr=&#8221;sudo route del default &amp;&amp; sudo route add default gw 10.0.0.1&#8243;</p>
<p>#Wake on lan shorcuts<br />
alias wdebian=&#8221;sudo etherwake 8C:89:A5:C1:D2:8A&#8221;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p># Meta-u to chdir to the parent directory<br />
bindkey -s &#8216;\eu&#8217; &#8216;^Ucd ..; ls^M&#8217;</p>
<p>bindkey &#8216;\e[1~&#8217; beginning-of-line<br />
bindkey &#8216;\e[4~&#8217; end-of-line<br />
bindkey &#8216;\e[7~&#8217; beginning-of-line<br />
bindkey &#8216;\e[8~&#8217; end-of-line<br />
bindkey &#8216;\eOH&#8217; beginning-of-line<br />
bindkey &#8216;\eOF&#8217; end-of-line<br />
bindkey &#8216;\e[H&#8217; beginning-of-line<br />
bindkey &#8216;\e[F&#8217; end-of-line<br />
bindkey &#8216;\e[5~&#8217; beginning-of-history<br />
bindkey &#8216;\e[6~&#8217; end-of-history<br />
bindkey &#8216;\e[3~&#8217; delete-char</p>
<p>#Enable auto correct for commands<br />
setopt correct</p>
<p># Pipe the current command through less<br />
bindkey -s &#8220;\el&#8221; &#8221; 2&gt;&amp;1|less^M&#8221;<br />
zstyle &#8216;:completion:*:(all-|)files&#8217; ignored-patterns &#8216;(|*/)CVS&#8217;<br />
zstyle &#8216;:completion:*:cd:*&#8217; ignored-patterns &#8216;(*/)#CVS&#8217;</p>
<p>#Mode verbose pour cp, rm, chmod, chown et rename<br />
for c in cp rm chmod chown rename; do<br />
alias $c=&#8221;$c -v&#8221;<br />
done</p>
<p>#Pendunt une complétion affiche les points<br />
expand-or-complete-with-dots() {<br />
echo -n &#8220;\e[31m&#8230;&#8230;\e[0m&#8221;<br />
zle expand-or-complete<br />
zle redisplay<br />
}<br />
zle -N expand-or-complete-with-dots<br />
bindkey &#8220;^I&#8221; expand-or-complete-with-dots</p>
<p>setopt EXTENDED_GLOB<br />
setopt NO_BEEP<br />
export EDITOR=&#8221;vi&#8221;<br />
setopt ZLE<br />
setopt AUTO_CD</p>
<p>##################<br />
# Completion Stuff<br />
##################<br />
bindkey -M viins &#8216;\C-i&#8217; complete-word</p>
<p># Faster! (?)<br />
zstyle &#8216;:completion::complete:*&#8217; use-cache 1<br />
# generate descriptions with magic.<br />
zstyle &#8216;:completion:*&#8217; auto-description &#8216;specify: %d&#8217;</p>
<p># Don&#8217;t prompt for a huge list, page it!<br />
zstyle &#8216;:completion:*:default&#8217; list-prompt &#8216;%S%M matches%s&#8217;</p>
<p># Don&#8217;t prompt for a huge list, menu it!<br />
zstyle &#8216;:completion:*:default&#8217; menu &#8216;select=0&#8217;</p>
<p># Have the newer files last so I see them first<br />
zstyle &#8216;:completion:*&#8217; file-sort modification reverse</p>
<p># color code completion!!!! Wohoo!<br />
zstyle &#8216;:completion:*&#8217; list-colors &#8220;=(#b) #([0-9]#)*=36=31&#8243;</p>
<p>unsetopt LIST_AMBIGUOUS<br />
setopt COMPLETE_IN_WORD</p>
<p># Separate man page sections. Neat.<br />
zstyle &#8216;:completion:*:manuals&#8217; separate-sections true</p>
<p># Egomaniac!<br />
zstyle &#8216;:completion:*&#8217; list-separator &#8216;fREW&#8217;</p>
<p># complete with a menu for xwindow ids<br />
zstyle &#8216;:completion:*:windows&#8217; menu on=0<br />
zstyle &#8216;:completion:*:expand:*&#8217; tag-order all-expansions</p>
<p># more errors allowed for large words and fewer for small words<br />
zstyle &#8216;:completion:*:approximate:*&#8217; max-errors &#8216;reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) )&#8217;</p>
<p># Errors format<br />
zstyle &#8216;:completion:*:corrections&#8217; format &#8216;%B%d (errors %e)%b&#8217;</p>
<p># Don&#8217;t complete stuff already on the line<br />
zstyle &#8216;:completion::*:(rm|vi):*&#8217; ignore-line true</p>
<p># Don&#8217;t complete directory we are already in (../here)<br />
zstyle &#8216;:completion:*&#8217; ignore-parents parent pwd</p>
<p>zstyle &#8216;:completion::approximate*:*&#8217; prefix-needed false</p>
<p>#}}}</p>
<p>export GREP_COLOR=31<br />
alias grep=&#8217;grep &#8211;color=auto&#8217;</p>
<p>#{{{ Prompt!<br />
colors<br />
host_color=cyan<br />
history_color=yellow<br />
user_color=green<br />
root_color=red<br />
directory_color=magenta<br />
error_color=red<br />
jobs_color=green</p>
<p>host_prompt=&#8221;%{$fg_bold[$host_color]%}%m%{$reset_color%}&#8221;<br />
jobs_prompt1=&#8221;%{$fg_bold[$jobs_color]%}(%{$reset_color%}&#8221;<br />
jobs_prompt2=&#8221;%{$fg[$jobs_color]%}%j%{$reset_color%}&#8221;<br />
jobs_prompt3=&#8221;%{$fg_bold[$jobs_color]%})%{$reset_color%}&#8221;<br />
jobs_total=&#8221;%(1j.${jobs_prompt1}${jobs_prompt2}${jobs_prompt3} .)&#8221;<br />
history_prompt1=&#8221;%{$fg_bold[$history_color]%}[%{$reset_color%}&#8221;<br />
history_prompt2=&#8221;%{$fg[$history_color]%}%h%{$reset_color%}&#8221;<br />
history_prompt3=&#8221;%{$fg_bold[$history_color]%}]%{$reset_color%}&#8221;<br />
history_total=&#8221;${history_prompt1}${history_prompt2}${history_prompt3}&#8221;<br />
error_prompt1=&#8221;%{$fg_bold[$error_color]%}&lt;%{$reset_color%}&#8221;<br />
error_prompt2=&#8221;%{$fg[$error_color]%}%?%{$reset_color%}&#8221;<br />
error_prompt3=&#8221;%{$fg_bold[$error_color]%}&gt;%{$reset_color%}&#8221;<br />
error_total=&#8221;%(?..${error_prompt1}${error_prompt2}${error_prompt3} )&#8221;</p>
<p>case &#8220;$TERM&#8221; in<br />
(screen)<br />
function precmd() { print -Pn &#8220;\033]0;S $TTY:t{%100&lt;&#8230;&lt;%~%&lt;&lt;}\007&#8243; }<br />
;;<br />
(xterm)<br />
directory_prompt=&#8221;%{$fg[$directory_color]%}%~%{$reset_color%} &#8221;<br />
;;<br />
(*)<br />
directory_prompt=&#8221;%{$fg[$directory_color]%}%~%{$reset_color%} &#8221;<br />
;;<br />
esac</p>
<p>if [[ $USER == root ]]; then<br />
post_prompt=&#8221;%{$fg_bold[$root_color]%}%#%{$reset_color%}&#8221;<br />
else<br />
post_prompt=&#8221;%{$fg_bold[$user_color]%}%#%{$reset_color%}&#8221;<br />
fi<br />
fg_light_gray=$&#8217;%{\e[0;34m%}&#8217;<br />
PS1=&#8221;${host_prompt} ${jobs_total}${history_total} ${error_total}${post_prompt} &#8221;<br />
RPROMPT=&#8221;%{$fg_bold[$user_color]%}&lt;%{$reset_color%} ${directory_prompt}${fg_light_gray}[%*]%{$reset_color%}&#8221;<br />
#}}}<br />
#Type f to flush the console to history file<br />
alias f=&#8221;fc -W&#8221;</p>
<p>HISTSIZE=10000<br />
SAVEHIST=10000<br />
HISTFILE=~/.history</p>
<p>setopt LIST_PACKED</p>
<p>#Append to history file instead of re-writing<br />
setopt APPEND_HISTORY</p>
<p>#To share history between terminal, not what I want as I always have multiple terminals like one for generating packet, the other to receive them<br />
#setopt SHARE_HISTORY</p>
<p>#Remove blanks<br />
setopt hist_reduce_blanks<br />
#Remove duplicates<br />
setopt hist_ignore_all_dups<br />
#Do not store commands in history starting with white space<br />
setopt hist_ignore_space</p>
<p>#Init<br />
autoload -U compinit promptinit zcalc zsh-mime-setup<br />
compinit<br />
promptinit<br />
zsh-mime-setup[/code]</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/my-zshrc/">My .ZSHRC</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
