<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vitalii Rybka on Medium]]></title>
        <description><![CDATA[Stories by Vitalii Rybka on Medium]]></description>
        <link>https://medium.com/@var_bin?source=rss-12008ab37e60------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*vfV4QlOocCfJr_iOSjr5KA.jpeg</url>
            <title>Stories by Vitalii Rybka on Medium</title>
            <link>https://medium.com/@var_bin?source=rss-12008ab37e60------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:56:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@var_bin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AngularJS + Webpack = lazyLoad]]></title>
            <link>https://medium.com/@var_bin/angularjs-webpack-lazyload-bb7977f390dd?source=rss-12008ab37e60------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb7977f390dd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Vitalii Rybka]]></dc:creator>
            <pubDate>Tue, 23 Jan 2018 21:03:52 GMT</pubDate>
            <atom:updated>2018-01-23T21:03:52.512Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pFRVxW3KkNuHuUhAchPVWA.jpeg" /></figure><h3>Introduction</h3><p>One of the common problems most developers encounter with when writing Single Page Application is creating and loading lazyLoad modules in response to a certain action taken by a user or clicking on URL (in most cases) that would load a set of dependencies such as JavaScript, CSS, HTML etc. In the realities of modern Front-End development that would be a huge JavaScript file. Well, in this article I would like to share my experience and show you how to realize lazyLoad modules on AngularJS and decrease the start time when you first run an application.</p><h3>Why AngularJS 1.x</h3><p>You may wonder “Why work with AngularJS 1.x if <a href="https://twitter.com/angular/status/951171093879865344">Angular v5.2</a> is available?” The question is more than appropriate. However, do not forget that many projects still use AngularJS 1.x and feel pretty good. For them, as well as for many other branches, switching to a new version would be expensive both in man-hours and money-wise. AngularJS 1.x remains in high demand in the market.</p><h3>Bicycles that already exist</h3><p>It has become a common thing that in the world of Front-End development there’s a great number of tools/approaches which can be used to solve the same issue and everyone tends to choose the one that fits his needs, skills, and knowledge best. And this isn’t necessarily a bad thing. You should accept this and go on developing. Someone chooses <a href="http://requirejs.org/">RequireJS</a>, someone opts for <a href="https://github.com/cujojs/curl">curl.js</a>, someone goes for <a href="http://browserify.org/">Browserify</a>, someone gives preference to [paste your favorite tool]. In this article I’d like to show you how to realize lazyLoad modules loading using <a href="http://webpack.js.org/">Webpack</a>, <a href="https://ui-router.github.io/ng1/">UI-Router</a>, and <a href="https://oclazyload.readme.io/">ocLazyLoad</a>. All behind-the-scene magic will be done with the help of ocLazyLoad tool. If we try to create a lazyLoad module using, for example, require.ensure without ocLazyLoad, we will receive the type of error like this one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NrgZ9ijmN1lItemYxLrW8A.jpeg" /></figure><h3>The Project Structure</h3><p>Here goes. Since I cannot provide access to the original code of the project for which I had to realize lazyLoad modules, I’ve created a small application. I tried to make it as simple as possible so that it didn’t look like a star probe vehicle and you could clearly see what comes from what. The main objective was to create a working prototype which would be <a href="https://angularjs-lazyload.herokuapp.com/">accessible online</a> (<a href="https://github.com/var-bin/angularjs-lazyload">not only sources</a>). A little bit below you’ll find the project structure for the branches require-ensure and system-import. For the branch import-es6 we’ll amend some addition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae20b6df900b42ff67b5b6eec604a8f2/href">https://medium.com/media/ae20b6df900b42ff67b5b6eec604a8f2/href</a></iframe><p>Now, before we proceed to the code, I would like to emphasize on <strong>two important points</strong> which directly affect whether we’ll get a lazyLoad module or not:</p><ol><li>In order for the module to become lazyLoad, one shouldn’t determine it as a dependency in relation to other modules.</li><li>The module cannot be imported anywhere except for the route for which you’d like to create this lazyLoad module.</li></ol><p>Do not worry if that doesn’t sound clear just yet. In practice, you’ll quickly learn what’s what.</p><h3>require.ensure() + $ocLazyLoad</h3><p><a href="https://webpack.js.org/api/module-methods/#require-ensure"><strong>require.ensure</strong></a> was introduced by the webpack team in the first of its versions. This method allows developers to dynamically create separate files (called “chunks” in webpack terms) containing certain pieces of the code which would further be loaded to the user in response to a certain action. And although the said method at its core isn’t the best one available for fulfilling this task, if you still prefer it, there’s nothing wrong about it. This method will perfectly suit those who want to create lazyLoad modules without spending too much on refactoring. Below, you can find an example of applying require.ensure for loading index.module.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f9b98ba53524e1b01d6ef2f62ec5a0e/href">https://medium.com/media/5f9b98ba53524e1b01d6ef2f62ec5a0e/href</a></iframe><p>For about.module.js the code will be identical, with the only difference that the paths to a module and some other parameters will be slightly different. Below, you can see an example of using require.ensure for loading about.module.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57c93c17c832e87223da525fe89749fc/href">https://medium.com/media/57c93c17c832e87223da525fe89749fc/href</a></iframe><p>As you might have noticed all magic happens in this line: <br>$ocLazyLoad.load(module.HOME_ABOUT_MODULE);</p><p>There’s also one other way of defining the module which is by using an object: <br>$ocLazyLoad.load({ name: &quot;home.module&quot; });</p><p>The downside to this method, though, is that we restrict our freedom of actions. Suchwise, if we decide to rename the module in the future, we’ll have to make alterations in several fragments of the code. Also, you may make a typo when writing a new name of the module which is a very common problem. Well, if you ask me, <strong>I’d strongly recommend that you do not use this approach ever.</strong></p><p>I would like you to pay attention to one very important nuance regarding about.module.js and further loading apps to the user. Take a look at the screenshot below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FW7ep57xRZTg%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DW7ep57xRZTg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FW7ep57xRZTg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/60700aff47bf5c9511a7c7c582547969/href">https://medium.com/media/60700aff47bf5c9511a7c7c582547969/href</a></iframe><p>Clicking the Home/About link, two files will be loaded simultaneously: index.module.chunk.js and about.module.chunk.js. This happens so because home.about URL is subsidiary of the home URL. You should keep this in mind. Running a little bit ahead, in the last section we will add one more module with a new URL and see that it will load only one file and nothing more.</p><h3>System.import + $ocLazyLoad</h3><p>I have long been thinking whether to write about this approach or not and then decide in favor of doing so. <a href="https://webpack.js.org/api/module-methods/#import-"><strong>System.import</strong></a> is another construction derivative of the webpack command which despite <a href="https://github.com/webpack/webpack/releases/tag/v2.1.0-beta.28">being prohibited</a> still remains one of the implementation options offered. Furthermore, this construction continues working in new webpack versions. What I suspect is that this is so because of the compatibility reasons. If you use this construction in your project, I’ve got bad news for you — it is currently in a <strong>deprecated</strong> status. OK, let’s move on.</p><h3>Dynamic imports + $ocLazyLoad</h3><p>Perhaps you’ve already heard that <a href="https://developers.google.com/web/updates/2017/11/dynamic-import">Chrome 63 and Safari Technology Preview 24 released</a> a few updates and now developers can access dynamic imports. Yes, you’re right, those very dynamic imports that have been offered in <a href="https://github.com/tc39/proposal-dynamic-import">the specification</a>. <a href="https://github.com/webpack/webpack/issues/2163">Back in 2016</a>, the webpack team has first applied dynamic imports support. In this section we will add one more module to the root of pages directory, to make sure lazyLoad works correctly. The structure for the branch import-es6 is given below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a384f25f8da2fa87ab34903deea9c0de/href">https://medium.com/media/a384f25f8da2fa87ab34903deea9c0de/href</a></iframe><p>If you use neither <a href="https://babeljs.io/">Babel</a> nor <a href="https://www.typescriptlang.org/">TypeScript</a> in your project then everything will work straight out of the box. But you know as well as I do that in the realities of the modern Front End it is very difficult to write a code using neither of the two tools. Let’s take a closer look at Babel. At first we need to install an additional plugin for babel which understands the syntax of dynamic imports: <a href="http://babeljs.io/docs/plugins/syntax-dynamic-import/">syntax-dynamic-import</a>. If we don’t do this we will get an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XEEANIsHZPwCshrAVgVr4A.jpeg" /></figure><p>Then we need to add .babelrc with the given settings:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd27d801370e501138a7354a2ad7269f/href">https://medium.com/media/bd27d801370e501138a7354a2ad7269f/href</a></iframe><p>Now, here’s the second unpleasant error which you may see below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INn8WqzXKqF61Mcp4Y-5XA.jpeg" /></figure><p>Yes, that’s right, <a href="https://github.com/eslint/eslint/issues/7764">ESLint doesn’t understand dynamic imports either.</a> To correct this, what we need to do is install a special parser for ESLint <a href="https://github.com/babel/babel-eslint">babel-eslint</a> and once we do this, all will work smoothly. Now let’s add .eslintrc with the settings:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f63354da3c94f4857dc11dec7ca3e2e6/href">https://medium.com/media/f63354da3c94f4857dc11dec7ca3e2e6/href</a></iframe><p>The time has come for us to try out dynamic imports in business. Let’s test them using the new module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22df54b17557f53c756ed5428b895c57/href">https://medium.com/media/22df54b17557f53c756ed5428b895c57/href</a></iframe><p>As you may have noticed from the code, the webpack command has added a few pleasant perks to dynamic imports. Now we have an opportunity to specify both the name of the final chunk which will create webpack and the load method. To learn more about this option, <a href="https://webpack.js.org/api/module-methods/#import-">click here</a> to read. On the video below, we can see dynamic imports in work:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FRGdtlP9-Q8M%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRGdtlP9-Q8M&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRGdtlP9-Q8M%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a05e479031d4e6d7948f925f77e7bc9f/href">https://medium.com/media/a05e479031d4e6d7948f925f77e7bc9f/href</a></iframe><h3>Component vs. Template</h3><p>The property that we used for loading modules is component, however, if you prefer, you can use template instead. They work almost the same way with the only one difference: if you make a typo in the name of a component or the component will be unavailable for one reason or another, the console will contain an error and you may spend quite a while to find out what the problem is. If you use template, however, this error will not occur.</p><h3>Useful Links</h3><ol><li><a href="https://ui-router.github.io/guide/ng1/route-to-component">How to route to AngularJS 1.5 components</a></li><li><a href="https://ui-router.github.io/guide/lazyloading">Lazy loading in UI-Router</a></li><li><a href="https://github.com/var-bin/angularjs-lazyload">Source code on GitHub</a></li><li><a href="https://angularjs-lazyload.herokuapp.com/">Project on Heroku</a></li></ol><h3>Instead of Conclusion</h3><p>Using lazyLoad modules in the context of AngularJS apps is an excellent way to make your application less resource-intensive, more responsive and better distributed. Times change, requirements for applications grow and so does the amount of code which we deliver to the user. If earlier it was enough to assemble all code in one file, give it to the user and it was done and dusted now it’s become something of a luxury. There’s a tendency now to separate an application depending on the URL and allocate the common code.</p><p>That’s all for now. Thanks for your attention and special thanks to those who’ve read this article to the end.</p><blockquote>P.S. If you’ve had a similar experience in realizing lazyLoad modules for AngularJS applications — share your comments below.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb7977f390dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Console Into Mass. The Transit to the Light Side. Automatization of Routine Tasks]]></title>
            <link>https://medium.com/hackernoon/console-into-mass-the-transit-to-the-light-side-automatization-of-routine-tasks-af3200bd9a47?source=rss-12008ab37e60------2</link>
            <guid isPermaLink="false">https://medium.com/p/af3200bd9a47</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Vitalii Rybka]]></dc:creator>
            <pubDate>Tue, 07 Mar 2017 11:41:03 GMT</pubDate>
            <atom:updated>2017-07-17T16:07:17.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vq_L9GHHLQcs8KiozAL_2Q.jpeg" /></figure><h3>Introduction</h3><p>In spite of what we do and how fast we enter the commands, the reality is, we still can’t beat the performance of computers. From the other hand, if we keep repeating the same action multiple times, we can easily give computers a hard time, can’t we? You could write a bash script (your favorite programming language) and instead of entering the same commands, wasting your time and energy, run the script and have some time for yourself, sit back in a seat, think of the eternity, universe, or anything else that comes up on your mind.</p><p>In the <a href="https://medium.com/@var_bin/console-into-mass-bash-scripting-698f75c20163#.5c94xtuwi">previous article</a> we discussed the principles of bash programming. Today we will learn how to apply this knowledge in practice.</p><h4>Automatization Plan</h4><ol><li>Fast diff</li><li>Fast diff + Jira API</li><li>Clean _dist</li><li>Updating a large number of repositories</li><li>Cloning a large number of repositories</li><li>Useful aliases</li></ol><p>The given plan comprises some of the tasks that I do several times a day (sometimes even an hour) every day. Generally speaking, automatization is a unique and original process that allows automating anything you can think of. Hopefully, by the time you’ll have read this article to the end, you will come up with your own automatization plan on how to surpass your PC performance. So, before we get started, make yourself a cup of hot coffee and enjoy our adventure to the world of automatization with bash.</p><h3>Fast diff</h3><p>Personally, I prefer to use <a href="https://git-scm.com/">Git</a>. Creating diff is a frequent task that requires entering the following command:<br>git diff origin/master origin/&lt;branch-name&gt; &gt; &quot;${HOME}/diff/diff-&lt;branch-name&gt;.diff&quot;</p><p>&lt;branch-name&gt; — is the name of the branch for which we need to create diff</p><h4>The disadvantages of the given approach</h4><ol><li>Entering the command is done only manually</li><li>Risks to mistype the command</li><li>Not easy to remember</li></ol><p>If you use bash, however, these issues can be solved. You should be able to:</p><ol><li>Enter the command</li><li>Enter the name of the branch</li><li>Get diff</li></ol><blockquote>And do all this without a hitch.</blockquote><h4>This is how the end command looks</h4><p>gdd &lt;branch-name&gt;</p><h4>Automatize</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/196848b5fd63302004badb326a5736bc/href">https://medium.com/media/196848b5fd63302004badb326a5736bc/href</a></iframe><p>Now, instead of typing a long command, it’s enough to enter ./fast_diff.sh &lt;branch-name&gt;. The script will remind you of inputting the name of the branch in case you forget to do it.</p><h4>The final touch</h4><p>Coming at this point you may wonder about the end command since using the script as it isn’t exactly convenient, given that we’re still bound to the directory we use.</p><p>Let’s take a closer look how it’s possible to create a new command for the executive file, not writing a relative/absolute path to it every time.</p><p>Every user has a subdirectory ~/bin that stores executive files. If you don’t, you can easily create it. What makes its use so convenient is that all files there can be accessed by name and there’s no need to specify their paths. To this subdirectory I’ve moved gdd file used to create diff:<br>#!/bin/bash <br>&quot;${HOME}/htdocs/rybka/tools/fast_diff.sh&quot; &quot;$@&quot;</p><p><strong>Some important notes:</strong></p><ol><li>There’s no need to specify a file extension.</li><li>The attribute x should be specified in a clear way (chmod +x &lt;filename&gt;)</li><li>If you don’t find bin in $PATH variable, you should make it more apparent by typing: PATH=&quot;${PATH}:${HOME}/bin&quot;.</li></ol><p>Relaunch the terminal to make this file accessible. Now, in order to create diff, you only need to enter the given command:</p><p>gdd &lt;branch-name&gt;</p><p>If you don’t like an idea of creating a new file for each command, you can optimize this process using a symbolic link:</p><p>ln -s &quot;${HOME}/htdocs/rybka/tools/fast_diff.sh&quot; gdd</p><h3>Fast diff + Jira API</h3><p>If you use Jira or any other task manager with API, you can go even further. With the help of Jira API, for example, the diff can be assigned to a certain task. To do so, you will need to use <a href="https://curl.haxx.se/">cURL</a>.</p><h4>Solution algorithm</h4><ol><li>Run the script</li><li>Define task id</li><li>If the task id hasn’t been provided, send user a message</li><li>Given that all has been done correctly, we generate diff and assign it to a task</li></ol><h4>This is how the end command looks</h4><p>gdd_jira &lt;issue_id&gt;</p><h4>Automatize</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c376b03704ac753b1a02bc80e9b14cf7/href">https://medium.com/media/c376b03704ac753b1a02bc80e9b14cf7/href</a></iframe><p>As you’ve probably noticed, this time we don’t need to pass the name of the branch to the script. We can get it by performing a few simple manipulations with the git commands:<br>branch=$(git rev-parse — abbrev-ref HEAD)</p><h3>Clean _dist</h3><p>Before we go any further let’s see what _dist directory is used for. Simply said, it’s the place where all CSS, JavaScript, templates (<a href="https://pugjs.org/api/getting-started.html">Jade/Pug</a>, <a href="http://handlebarsjs.com/">Handlebars</a>, etc) and other files are saved after the launch of build system (<a href="http://gruntjs.com/">Grunt</a>, <a href="http://gulpjs.com/">Gulp</a>, etc). The directory doesn’t necessarily have to bear the _dist name. You can find many different variations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*s3X5XWUJhMX1-U-vsllLJg.jpeg" /></figure><p>For one of the projects we use Grunt. Quite often, though, our team have encountered with a problem that it doesn’t always seem to see a change in some of the files, <a href="http://lesscss.org/">Less</a> files in the majority. To solve this problem, though, you can clean the _dist directory for one or for all themes at once. To do this, you could also use Grunt, cleaning the directory manually, yet, it wouldn’t be same effective as it is with bash. There are much more directories here, not one or two, not even twenty. There are a lot of them. The main requirement for when working with the script is not to overload it with wrappers and/or dependencies without need.</p><p>Let’s see how the same can be done with the power of shell:<br>find &lt;path-to-themes&gt; -type d -name &quot;_dist&quot; | xargs rm -rfv</p><p>&lt;path-to-themes&gt; — the path to the directory with the themes</p><p>The disadvantages of the given approach are the same as in the case of the diff creation. Plus, there’s no option to specify one theme that we’d like to delete _dist directory from.</p><h4>Solution algorithm</h4><ol><li>Run the script</li><li>If you don’t have the name of the theme, you can delete _dist directory for all of them</li><li>If you have a certain theme name, delete _dist for only this one</li></ol><h4>This is how the end command looks</h4><p>clean_dist [&lt;theme_name&gt;]</p><h4>Automatize</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/586707fa58ac70ef46256d3e5c57c502/href">https://medium.com/media/586707fa58ac70ef46256d3e5c57c502/href</a></iframe><h3>Updating a large number of repositories</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*lsurkA-acsbTiU-2d15WTw.jpeg" /></figure><p>Imagine you work on a big project that contains a directory for third-party repositories which, even though you don’t create them, you still need to support and update. If they are two or three, that might not be a big problem, although, personally I’d not be so confident.</p><blockquote>But what if you’ve got more than 10–15 repositories to support?</blockquote><p>You’d need to spend a lot of time tracking them constantly. Why not automatize this process then?</p><h4>Solution algorithm</h4><ol><li>Go to the directory with a repository</li><li>Check whether a repository is in the master branch</li><li>If it’s not there, run git checkout</li><li>Then git pull</li></ol><p><strong>An important note. </strong>Even if a repository has switched to master branch, there’s still a chance it might be not updated. With that in mind, running git pull ought to be done anyway.</p><h4>This is how the end command looks</h4><p>up_repo</p><h4>Automatize</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5265ad81f481c05f6a0d02d72f585aa/href">https://medium.com/media/a5265ad81f481c05f6a0d02d72f585aa/href</a></iframe><h3>Cloning a large number of repositories</h3><p>This process is closely connected to the previous one. To make it possible for a user to use a previous command in practice. I need to provide him/her with a repository of third-party developers adding it into a bash/core/vendors directory (a user doesn’t necessarily need to be aware of it). On the analogy of npm modules, this repository shouldn’t go alongside the main one. All a user should do is execute the command and wait until after the cloning of all repositories is completed.</p><h4>Solution algorithm</h4><ol><li>The list of repositories is set as an array</li><li>Run the array cycle</li><li>Pay a particular attention if a vendor has more than one repository</li><li>Run a few more additional checkups</li><li>Execute git clone</li></ol><h4>This is how the end command looks</h4><p>clone_repo</p><h4>Automatize</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65d6e1213480999faebec18c36f86641/href">https://medium.com/media/65d6e1213480999faebec18c36f86641/href</a></iframe><h3>Useful aliases</h3><p>I’d like to ask my reader a couple of questions and I’d like you to answer them honestly. How often do you use this command?<br>git branch</p><p>What about this command?<br>git status</p><p>And this one?<br>git push origin &lt;branch-name&gt;</p><p>Do you often use this one?<br>ps aux | grep &lt;user-name&gt;</p><p>This list can be extended and more likely than not, everyone has got his/her frequently used commands. So, here is where you may suddenly think that for all these commands it’d be a sensible idea to create aliases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qho7T74ivpZyc5Ftb4NTDw.jpeg" /></figure><p>In the list below you’ll find some of the aliases that I use on a daily basis:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e31d60122c05626270af17b8366e96fc/href">https://medium.com/media/e31d60122c05626270af17b8366e96fc/href</a></iframe><p>In order to check what aliases have been set, you want to run the command alias but without specific parameters.</p><h4>Where to save aliases</h4><p>To create a permanent alias, add it into .bashrc file in a user’s home (~) directory. You could also add it into .gitconfig file for working with git.</p><h4>Don’t change aliases late at night</h4><p>Alias is a powerful tool. Yet, here is all as with passwords.</p><blockquote>Don’t change your aliases when you’re about to go to bed.</blockquote><p>I did happen to change one late at night. What happened next you can guess. I didn’t remember I’d done it and I spent most part of a day trying to figure out why nothing worked.</p><h3>In conclusion</h3><p>When I just got into the principles of bash, my first thought was: “Stop, aren’t they what system administrators need?”. Yet, I did understand the importance of this knowledge that would allow me to lighten the burden of daily routine tasks. Today, I can say with confidence that if your work is anyhow related to remote servers or OS *nix,or you work with Windows OS (<a href="https://blogs.msdn.microsoft.com/commandline/2016/04/06/bash-on-ubuntu-on-windows-download-now-3/">Bash on Ubuntu on Windows</a>, <a href="https://blogs.msdn.microsoft.com/wsl/2016/10/19/windows-and-ubuntu-interoperability/">Windows and Ubuntu Interoperability</a>), the knowledge and understanding of the principles of bash will come absolutely useful.</p><blockquote>Simply put, a script is nothing more than a basic list of system commands, written all in one file.</blockquote><p>Using this file, though, can simplify executing a lot of routine tasks that otherwise, you’d do manually.</p><p>Here are a few links with bash capabilities, some of which I’ve shown in my examples:</p><ol><li><a href="http://tldp.org/LDP/abs/html/io-redirection.html">I/O Redirection</a></li><li><a href="http://tldp.org/LDP/abs/html/functions.html">Functions</a></li><li><a href="http://tldp.org/LDP/abs/html/arrays.html">Arrays</a></li><li><a href="http://tldp.org/LDP/abs/html/dblparens.html#CVARS">The Double-Parentheses Construct</a></li><li><a href="http://tldp.org/LDP/abs/html/special-chars.html">Special Characters (pipe)</a></li><li><a href="http://tldp.org/LDP/abs/html/exit-status.html">Exit and Exit Status</a></li><li><a href="http://tldp.org/LDP/abs/html/aliases.html">Aliases</a></li><li><a href="http://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path">How to add paths to $PATH variable</a></li></ol><p>That’s it. Thanks for your attention and special thanks to those who’ve read the article to the end.</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af3200bd9a47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/console-into-mass-the-transit-to-the-light-side-automatization-of-routine-tasks-af3200bd9a47">Console Into Mass. The Transit to the Light Side. Automatization of Routine Tasks</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Console Into Mass. The Transit to the Light Side. Bash-scripting]]></title>
            <link>https://medium.com/@var_bin/console-into-mass-bash-scripting-698f75c20163?source=rss-12008ab37e60------2</link>
            <guid isPermaLink="false">https://medium.com/p/698f75c20163</guid>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[bash]]></category>
            <dc:creator><![CDATA[Vitalii Rybka]]></dc:creator>
            <pubDate>Thu, 26 Jan 2017 20:57:12 GMT</pubDate>
            <atom:updated>2017-01-27T06:42:23.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*661S25dNfoGFhm2eSDFCUA.jpeg" /></figure><h3>Introduction</h3><p>A tool is convenient to use only if it helps solve a certain task. It’s also important that the tool is adjustable to particular user’s needs. An ability to expand it functionality would be an added bonus.</p><p>Finally, we’ve got on to one of the most interesting and fascinating topics — bash-scripting. Every time you launch a terminal, it automatically starts to run a shell command interpreter which understands and processes commands you’ve typed on a keyboard. A shell also signals errors and watches out for compliance of the commands with their syntax. Here are some of the examples of these commands: <em>change directory, create a new directory, add a text file, edit a text file, save changes, etc.</em></p><p>The list of shell software is quite big today, yet sh is still recognized as the standard. Developed by Stephen Bourne in 1977 it was actually the first release of the command line interfaces that soon became a big success (<a href="https://en.wikipedia.org/wiki/Bourne_shell">wiki</a>). In 99% cases, users working on OS *nix driven computers have bash as the default shell command interpreter. You could also find zsh shell, but let’s save this story for another time.</p><p><strong>The important note.</strong> This article isn’t a full bash-scripting guide but a rundown of the bash-programming basics with examples. It should help readers learn some of the fundamentals to use in practice further on. In the end of the article I give some useful links with more detailed information on the subject.</p><h3>The Basics</h3><p>The first part will be all about the basics. We will look into the concept of scripting, see how to start a script, how to determine its variables and how to assign their values. I will also provide some tips on how to pass arguments to a bash script and work with them. The seconds part will be about the branching, while in the third one I will focus on cycles.</p><p>Whatever bash-based script you take, its first line will always be the same:</p><p>#!/bin/bash</p><p>This is also the way how we tell the command interpreter which application to run. To improve code portability, you could enter it this way:</p><p>#!/usr/bin/env bash</p><p>When done this way, you make it easier for the system to interpret the command correctly. This is also a necessary step to do if you often work on different OSes or PC. If not, the first command will work just fine. In all my examples I used it too.</p><p>All files that a user creates are not executable by default and require specifying this parameter by entering the command:</p><p>chmod +x &lt;filename&gt;</p><p>You could run a non-executable script too, by typing:</p><p>bash &lt;filename&gt;</p><h4>Variables</h4><p>Variable is a special area in computer memory with its own name that refers to a certain memory cell. As a rule, variables are used to hold information and comprise two key elements: <em>a name </em>and<em> a value</em>.</p><p><strong>Name:</strong></p><ul><li>Letters, numbers, underline (_).</li><li>Cannot start with a number.</li></ul><p><strong>Value:</strong></p><ul><li>Numbers, strings (in double quotes if with spacings), characters.</li></ul><p><strong>How to create (overwrite) a variable:</strong></p><p>path=&quot;$HOME&quot;</p><blockquote>Pay attention that we put spacing neither before nor after equal sign.</blockquote><p><strong>Reading variables:</strong></p><p>&quot;$path&quot; or &quot;${path}&quot;</p><p>In most cases two variants work equally well. However, if the command hasn’t been interpreted correctly or looks confusing, you should stick with the &quot;${path}&quot; only.</p><h4>Passing arguments to a bash script</h4><p>./script.sh arg1 arg2 arg3 … argN</p><p><strong>How to process arguments in a bash script:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e361d88901d05fa339012084107e5e4/href">https://medium.com/media/7e361d88901d05fa339012084107e5e4/href</a></iframe><p>It’s time to create the first script. As it is always the case, a user will see the welcome phrase “Hello, world!”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4eeb3898a7f274b4b1135207aead9cc/href">https://medium.com/media/d4eeb3898a7f274b4b1135207aead9cc/href</a></iframe><p>This is how easy it is to show the work of bash script by such a simple example. Let’s consider a different example and practice a bit with variables and arguments, passing them to a script. All examples that I give in this article can be found in the <a href="https://github.com/var-bin/terminalForCoder__WSD">repository</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0070848473cf6d4367a569d17fe960d/href">https://medium.com/media/d0070848473cf6d4367a569d17fe960d/href</a></iframe><blockquote>Please, note, all bash-based scripts have a .sh extension.</blockquote><h3>Branching</h3><p>So, now after we’ve already learnt some of the basics and practiced with variables a bit, let’s try to work with branching. For working with branches we will need to use the following statements:</p><ol><li>if</li><li>if/else</li><li>if/elif/else</li><li>case/in/esac</li></ol><p>The first three of them are pretty similar, each next line supplementing the other. Let’s have a look at the simplest one:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abf6760de05235a55629e579e03c9f53/href">https://medium.com/media/abf6760de05235a55629e579e03c9f53/href</a></iframe><p>As you’ve noticed, there’s no semi-comma at the end of the lines. However, if you need to write statements (and not only) in one line, putting semi-commas will be necessary.</p><p>Working with branches, it’s also important to check whether the string is blank or not, if the number equals zero, whether we work with a file or with a directory, etc. To allow you to accomplish these and other tasks, bash utilizes its unique syntax. I figuratively divided it into four categories: <em>strings, numbers, files and boolean</em>. Let’s take a close look at each of them:</p><h4>Conditions (strings):</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26e1783777f24e540806839b394d45e9/href">https://medium.com/media/26e1783777f24e540806839b394d45e9/href</a></iframe><h4>Conditions (numbers/strings):</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3ce67e924c582ef11d2fe9b519bfdef/href">https://medium.com/media/c3ce67e924c582ef11d2fe9b519bfdef/href</a></iframe><h4>Conditions (files):</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9f66aa130c0758364f0ea61717ffc80/href">https://medium.com/media/a9f66aa130c0758364f0ea61717ffc80/href</a></iframe><h4>Conditions (boolean):</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/255f68989f593a0f780125cbf6b07615/href">https://medium.com/media/255f68989f593a0f780125cbf6b07615/href</a></iframe><p>Let’s skip if/else statement but linger round if/elif/else:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ef737aa6f57ceb2751d634816ffe493/href">https://medium.com/media/8ef737aa6f57ceb2751d634816ffe493/href</a></iframe><p>The script expects to receive one output argument containing the name of a file or the name of a directory. After the checking of argument is done, you will know what to do next. If this is a true file or directory, you can delete it, if not, you will need to send a user a message that deletion isn’t possible.</p><p>Now, let’s get a look at the last statement in the branch — case/in/esac. If drawing analogy with JavaScript, it would be an alternative to switch/case directive. Here’s the example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38eb409fe5bb02cb04fad476611d3e99/href">https://medium.com/media/38eb409fe5bb02cb04fad476611d3e99/href</a></iframe><p>The given script expects to receive two numeric arguments: one and two, and depending on their order, it will create either file or directory. You will also need to run the check to see whether the number of arguments complies with the number typed in by a user and there are no less than two. If the arguments aren’t correct (which we can see from the value assigned by default), we send a user a message.</p><h3>Cycles</h3><p>In this part we will consider some of the examples how to work with cycles. To organize cycles, bash uses the following statements: for/in and while.</p><p>Here’s the example of for/in syntax:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/457976fc6e78f343c9a4b793139f70ab/href">https://medium.com/media/457976fc6e78f343c9a4b793139f70ab/href</a></iframe><p>Where i is the name of variable that an array will be passed to. During each next iteration i will gain the following array value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8c88051d302f9ae85bdd20dbed5eb01/href">https://medium.com/media/a8c88051d302f9ae85bdd20dbed5eb01/href</a></iframe><p>The list of values comprises 1 2 3 4 5. Let’s run a cycle that will go through each of the values. Then create the variable file_name. Check next whether a file with the same name already exists. If not, you will need to create it, if it does, skip this step.</p><p>The word continue here is a keyword that allows skipping iteration and proceeding to work, while the word break allows stopping script execution. Both these words are used in the frame of if/else statement only.</p><p>Let’s see how the while statement works:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45f95c821e77547bc78c5cd860f5557a/href">https://medium.com/media/45f95c821e77547bc78c5cd860f5557a/href</a></iframe><p>And consider the example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5a649a609a2356d670dbee97361c984/href">https://medium.com/media/a5a649a609a2356d670dbee97361c984/href</a></iframe><p>In the given example the ninth and the thirteenth lines contained the key word read. As long as $again variable equal the value &quot;yes&quot; , the program will ask you to enter a user’s name in order output it on a screen. Then you will be asked if you want to proceed. You will receive these messages until you either enter any other line but &quot;yes&quot; or press Enter. Yet, the code in the ninth line containing $name being not declared before looks much more interesting. This is a dynamic variable that’s been created when the program is run.</p><h3>Useful links</h3><ol><li><a href="https://github.com/denysdovhan/bash-handbook">bash-handbook</a></li><li><a href="http://tldp.org/LDP/abs/html/">Advanced Bash-Scripting Guide</a></li><li><a href="https://google.github.io/styleguide/shell.xml">Shell Style Guide from Google</a></li><li><a href="https://www.codecademy.com/learn/learn-the-command-line">Learn the Command Line</a></li><li><a href="https://learnpythonthehardway.org/book/appendixa.html">The Command Line Crash Course</a></li><li><a href="https://www.youtube.com/watch?v=3DA1grSp4mU">Basic Unix commands</a></li></ol><h3>In conclusion</h3><p>Let us end the introduction with bash on this positive note. The given information should be enough for readers to start working with simple scripts and automating most routine tasks.</p><p>With reference to my next article I’d like to tell readers that it will contain less theory but more examples on how to automate routine tasks with the help of bash scripts. Keep following up.</p><p>This is all for now. Thanks for your attention and special thanks to those who’ve read the article to the end. Meet you soon again!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=698f75c20163" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Console Into Mass. The Transit to the Light Side. Part Two.]]></title>
            <link>https://medium.com/@var_bin/console-into-mass-the-transit-to-the-light-side-part-two-6ffa79dd1a5e?source=rss-12008ab37e60------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ffa79dd1a5e</guid>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vitalii Rybka]]></dc:creator>
            <pubDate>Wed, 11 Jan 2017 09:08:27 GMT</pubDate>
            <atom:updated>2017-01-11T09:08:27.648Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzQr_lAE-zw9L1Txel4ioA.png" /></figure><h3>Introduction</h3><p><a href="https://medium.com/@var_bin/console-into-mass-the-transit-to-the-light-side-81766a3d7fff#.vo5plgq54">I’d used screen</a> for quite a long time before I knew it was not enough for me anymore and I started to look for alternatives. Around the same time I found tmux, a software application described by many users as a screen based on steroids. I couldn’t understand this strange comparison until I tried the app for myself. Honestly speaking it didn’t happen instantly that I started to work with tmux only. After three-four attempts I still got back to using screen. Eventually, though, tmux has won.</p><p><strong>The important note:</strong> I’d like to make a point that a reader is expected to have no access to the graphic shell. All tools he/she has got are a terminal (<a href="https://en.wikipedia.org/wiki/Command-line_interface">CLI</a>) and an array of commands to enter.</p><h3>Installation</h3><p>So, let’s get to the tmux installation. Actually, the installation requires entering the first command and after that a user can launch it on each next input of the command tmux in the terminal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fdd0d3363ebd429cc3d4bf9b67f01b9/href">https://medium.com/media/8fdd0d3363ebd429cc3d4bf9b67f01b9/href</a></iframe><p>More advanced users have got an opportunity to build tmux from the <a href="https://github.com/tmux/tmux">repository</a> or download it as an archive file on PC. The step-by-step instructions are given <a href="https://raw.githubusercontent.com/tmux/tmux/master/README">here</a>.</p><h3>Basic Key Combinations</h3><p>Same for when using screen, you don’t need to learn these key combinations by heart. Follow this <a href="https://github.com/var-bin/terminalForCoder__WSD/blob/master/tmux/hotkey.md">link</a> and start to use them instead. The only thing which might confuse you from the start is that the key combinations are different from those used for screen. If needed, however, they can be changed to the ones you prefer in the configuration file.</p><h3>Configuration</h3><p>Tmux boasts quality default settings out-of-the-box. There’s no need to customize the arrangement and backlight of the control pane how you’d have to do it in screen. But if you’d need a configuration file, keep in mind that it’s got to have a name .tmux.conf; it ought to be transferred to a home user’s directory.</p><p>I’d like to tell you about a useful setting that saved me the trouble of creating a new tmux session every time I used it. Let me describe it in details. I’ve got a Windows OS driven PC and to connect with the remote server I use <a href="http://www.putty.org/">putty</a> and pagent (for adding keys). With each new key being added to pagent, I need to enter a password (a passphrase that you provide when creating ssh keys). In putty each new connection needs selecting this checkbox:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*gsHzI7hua29ldaRlYGSBfg.jpeg" /></figure><p>These are the peculiarities of the work of Windows + putty + remote connection via SSH. Putting the tick in this checkbox is required to make SSH-agent forwarding work.</p><p>Ok, let’s get back to the problem. In case you happen to lose a connection with the network or if the power in the office is gone, tmux will save your session and after you reconnect, will prompt you to enter your password to the key.</p><p>This is the scenario that will take place all the time. This also means that SSH-agent forwarding will stop to work. What you can do, though, is to end the current tmux session and reconnect to the remote server. It isn’t a critical issue, of course, but looking at it in a long perspective, this can become an irritating extra step to do. Well, there’s a solution, you only need to open your home directory, find the file .bashrc and change there a few settings.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64f1f7cbec3dc206c67115df2c9dc8c6/href">https://medium.com/media/64f1f7cbec3dc206c67115df2c9dc8c6/href</a></iframe><p>I will try to explain what happens when you connect to the remote server with the SSH-agent forwarding working. The moment an ssh-client (putty in our case) connects with the remote server, it creates a socket which a user gets the key through, with a variable $SSH_AUTH_SOCK inherited by the running shell (that processes user’s commands) during the current session. Besides the said variable, the client creates $SSH_CLIENT, $SSH_CONNECTION, $SSH_TTY variables to store information about the current ssh-connection. Yet, the next time we will connect to the remote server, the client will create a new socket with new variables. That’s why we need to prompt shell of the data we’d like it to save and use on the next connection (if there are any).</p><h3>How tmux Works</h3><p>Now, it’s time to look into how tmux works. You already know how to launch it — it’s enough to enter tmux command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uNL5VstUWJ8k0QbZdzr3cQ.jpeg" /></figure><ol><li>Working area. Pane.</li><li>A status bar with tabs and other elements.</li><li>A tab with the default name.</li></ol><p>This is the layout you’ll see on opening tmux. If you’ve read my <a href="https://medium.com/@var_bin/console-into-mass-the-transit-to-the-light-side-81766a3d7fff#.vo5plgq54">previous post</a>, you’ve probably noticed that tmux and screen look pretty much similar with the only difference that in tmux a status bar comes by default. Ok, let’s see how tmux works when implementing a more complicated task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urXH5U0ZY5eNKw5GRs00EQ.jpeg" /></figure><p>For this purpose we will need to use <a href="https://github.com/var-bin/terminalForCoder__WSD">repository</a>. If you haven’t cloned it on your PC yet, enter the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53f64ad83892b11a8e0e57015087f04e/href">https://medium.com/media/53f64ad83892b11a8e0e57015087f04e/href</a></iframe><p>After that we need to launch tmux. Let’s work with the tabs first. We will need two-three tabs at a start. In order to create a new tab, you can use the following key combination:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa83d722992bee186d04d6d36b29b769/href">https://medium.com/media/fa83d722992bee186d04d6d36b29b769/href</a></iframe><p>The next step requires renaming tabs. To do this, use:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d6a93fee46305e1cab2704641023cf6/href">https://medium.com/media/7d6a93fee46305e1cab2704641023cf6/href</a></iframe><p>To switch between the tabs, use either this key combination:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2516f8efd0a6b127b984eeadec58a0a5/href">https://medium.com/media/2516f8efd0a6b127b984eeadec58a0a5/href</a></iframe><p>Now, after we’ve practiced with tabs a bit, let’s split the pane into two independent ones. Keep in mind, though, the layout isn’t going to be the same for the rest of the tabs. For each new tab tmux creates its unique layout. So, in order to split the pane, we need to press:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76294b3636f7e040a9c8d9b53aaae1b7/href">https://medium.com/media/76294b3636f7e040a9c8d9b53aaae1b7/href</a></iframe><p>Open some application (In my example I use <a href="https://midnight-commander.org/">midnight commander</a>) in the left pane by inputting the command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ab683280e5f4c3c4d223dc37a9afefe/href">https://medium.com/media/2ab683280e5f4c3c4d223dc37a9afefe/href</a></iframe><p>Shifting the panes can be done by pressing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdc7f8c9dfb9a1228a66c5e1e6056a2c/href">https://medium.com/media/bdc7f8c9dfb9a1228a66c5e1e6056a2c/href</a></iframe><p>In the right pane let’s run our test app. It’s a simple chat written in <a href="https://nodejs.org/">node.js</a> and <a href="http://socket.io/">socket.io</a> and taken from socket.io official website. What I added to it is a bit of logging in order to show you that it works. Let’s open directory now %repoName%/tmux/chat-example and enter the following commands:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13e166c5802182780c7c646c51c0b6a1/href">https://medium.com/media/13e166c5802182780c7c646c51c0b6a1/href</a></iframe><p>%repoName% — the directory’s name to which we’ve cloned repository before.</p><p>If you’ve done everything correctly, you will see the next line on the screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e1bb7f994796400c4c01ed92d2e0102/href">https://medium.com/media/5e1bb7f994796400c4c01ed92d2e0102/href</a></iframe><p>Open a browser and enter localhost:3000 in a new tab. Type some message in the entry line and press <em>“Enter”</em>. See? The same message is displayed in the terminal, in the pane where you entered the node index.js command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yplgOuHEa3ehqAnZy0_nCg.jpeg" /></figure><p>Like we’ve done with screen (described in the previous post), let’s simulate disconnection, click the cross to close the terminal but leave the browser running. Let’s type more messages in the entry line. They all keep appearing on the screen despite the terminal being closed a second ago. Everything works!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eap9kOS-oWSkGHsiVjHY5w.jpeg" /></figure><p>The current session along with all processes have been saved. Screen can save them too. So, what’s different then? Let’s reconnect to the session. Launch the terminal and enter the command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75a7db2bf8756cb1029b791a490292e4/href">https://medium.com/media/75a7db2bf8756cb1029b791a490292e4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59agkUfSlM9mu-HF1exOBg.jpeg" /></figure><p>You’ve probably noticed that the layout we’ve created before (vertically splitted) has been saved too and that’s already a great advantage of tmux over screen.</p><h3>Useful Links to Work With tmux</h3><ol><li><a href="https://gist.github.com/MohamedAlaa/2961058">A good crib note on tmux</a></li><li><a href="https://tmux.github.io/">The official website of tmux</a></li><li>man tmux =)</li></ol><h3>screen vs. tmux</h3><p>Drawing the line between screen and tmux, I’d say, use screen only when tmux isn’t available. E.g. you can neither build or download it. In all other cases it’d be much more sensible to start working with tmux.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffada949a85b5ee98cbec2329a0408ac/href">https://medium.com/media/ffada949a85b5ee98cbec2329a0408ac/href</a></iframe><p>Let’s make a summary of what’s been said above. We’ve seen one more terminal manager in work — tmux. We’ve learnt how to install and configure it. We’ve practiced some shortcut keys and seen how tmux works by giving it some task. We’ve also seen some of its obvious advantages over screen.</p><p>Of course, you can find a lot more terminal managers but screen and tmux, compatible with different OS to your liking, so it’s totally up to you which one to use.</p><p>That’s it for now. Thanks for your attention and time. Special thanks to the readers who’ve read the post to the end and see you soon, on my next post release.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ffa79dd1a5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Console Into Mass. The Transit to the Light Side]]></title>
            <link>https://medium.com/@var_bin/console-into-mass-the-transit-to-the-light-side-81766a3d7fff?source=rss-12008ab37e60------2</link>
            <guid isPermaLink="false">https://medium.com/p/81766a3d7fff</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vitalii Rybka]]></dc:creator>
            <pubDate>Wed, 04 Jan 2017 20:57:21 GMT</pubDate>
            <atom:updated>2017-03-07T12:54:28.652Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-D8wvsNGRSz2_VAkhCMeBg.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>Hi everyone! This is a text version on my speech given at <a href="https://wsd.events/2016/11/26/">WSD on the 26th of November in Kiev</a>. The idea of writing this post was to share some key aspects with a wider audience, provide more details on the important points that have been discussed at the conference, give some illustrated examples and hear your arguments and opinion back.</p><h3>The <em>Escape</em> Plan</h3><ol><li>Console manager. Part One.</li><li><a href="https://medium.com/@var_bin/console-into-mass-the-transit-to-the-light-side-part-two-6ffa79dd1a5e#.kt37rjbb6">Console manager. Part Two.</a></li><li><a href="https://medium.com/@var_bin/console-into-mass-bash-scripting-698f75c20163#.dldasj4h8">Bash-scripting</a></li><li><a href="https://medium.com/@var_bin/console-into-mass-the-transit-to-the-light-side-automatization-of-routine-tasks-af3200bd9a47#.btof6qmfk">Routine Tasks Automation</a></li></ol><p><strong>The important note</strong>: a reader is expected to be a confident <em>*nix OS</em> user. Further in my examples, I will refer to many different utilities such as grep, find, xargs, echo, sed, etc. yet without going deep into details. This was not my intention anyway.</p><p>I work in a big team and I often see how one and the same task assigned to several people can be fulfilled in several different ways. The sames goes for using a terminal. Meet IE6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*HjKvKxNqU9K7v34L2V8urw.gif" /></figure><p>Imagine your favorite browser cannot work with tabs. Worse than that, it simply shuts down at the most inappropriate moment and doesn’t restore a session for you to continue to work.</p><p>The majority of users, however, when hear of the term “<em>terminal”</em> picture a black screen with white characters on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kkKFFGziVwOcY8jVDWTeCg.jpeg" /></figure><p>Now let’s imagine the same browser but with a terminal where you could enter an array of commands such as<em> </em>git, npm, node<em>, </em>etc. right there. Sounds like a remote future prospect, however, it isn’t so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*i6JdioxnSSiUcSGQZ0rexw.gif" /></figure><p>In these series of articles I’d like to prove usability and multifunctionality of a terminal so that those, having experience of using it, could get the most out of it.</p><p>Let’s begin. The topics I’m going to cover include console managers, bash-scripting and routine automation through bash-scripting.</p><h3>Repository</h3><p>For your convenience, I’ve created a <a href="https://github.com/var-bin/terminalForCoder__WSD">repository</a> of all examples and topics reviewed in this post on github, so, you’ve got access to the download files and have a chance to practise these commands on your own PC.</p><h3>Slides</h3><p>Follow this <a href="http://var-bin.com/terminalForCoder__WSD-2016/en/shower/">link</a> to access the slides. The presentation has been based on <a href="https://github.com/shower/shower">shower</a> engine.</p><h3>Compatible OS</h3><p>All examples and topics I’m going to cover in my articles are cross-platform compatible (<a href="https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/">Windows 10 stable</a>, Mac OS X, <a href="https://www.ubuntu.com/download/desktop">Ubuntu</a>). I’ve chosen Ubuntu OS, and so, whatever you see next is related to the Ubuntu environment. You can also use this <a href="https://conemu.github.io/">ConEmu</a> console emulator, though, if you’d decide to input some commands in it, you wouldn’t be able to do this, unfortunately.</p><h3>Console managers. Part One. Screen.</h3><p>My first meeting with screen was an absolute haphazard. One of my colleagues who assisted me in my work took notice of that I don’t use screen. “We need to fix it”, he said, and installed the screen on my computer, customized it for me and taught several basic key combinations.</p><h3>Installation</h3><p>To install the screen, it’s enough to enter the first command. After you do that, you will be able to open screen whenever you need by simply typing the command screen in the terminal manager.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e243f5b9fdc5fe84c3d7d6a1526a3d5/href">https://medium.com/media/5e243f5b9fdc5fe84c3d7d6a1526a3d5/href</a></iframe><h3>Basic Key Combinations</h3><p>Why have I given a <a href="https://github.com/var-bin/terminalForCoder__WSD/blob/master/screen/hotkey.md">single link</a> instead of listing all key combinations? Well, it is all pretty simple. Firstly, they all can be found in the manual (man screen). Secondly, you don’t need to actually learn them by heart, all you need is to start using them.</p><h3>Configuration</h3><p>By default screen doesn’t look very convenient. The application has got quite a lot of excessive features including license info and lacks a status bar. The good thing is, all these can be fixed by transferring the configuration file to a user’s home directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcc232e1c2d9b43ae2ed5faf684e3885/href">https://medium.com/media/fcc232e1c2d9b43ae2ed5faf684e3885/href</a></iframe><h3>How screen Works</h3><p>Let’s take a look at how screen works. You already know how to launch it, all you need is to type screen in the terminal. Don’t forget to transfer the configuration file to a user’s home directory first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWcxZdXqgDGhTA1iv87t_g.jpeg" /></figure><ol><li>Working area. Layout.</li><li>A status bar with tabs and other elements.</li><li>A tab with the default name.</li></ol><p>This is how screen looks like after you open it. Now let’s see how it works giving it a bit more complicated task to perform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CGxAZaz_eSCsxI5oajLOOA.jpeg" /></figure><p>You will need to use a repository that I’ve mentioned above, so, better clone it to your PC.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53f64ad83892b11a8e0e57015087f04e/href">https://medium.com/media/53f64ad83892b11a8e0e57015087f04e/href</a></iframe><p>Open the terminal and enter screen. We’d need two-three tabs for a start. In order to create a new tab, press the following key combination:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f5e16b5617a50e67ec2f0303c7b1b02/href">https://medium.com/media/2f5e16b5617a50e67ec2f0303c7b1b02/href</a></iframe><p>The next thing to do is to rename these tabs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b06a77e93534baf80fa14782be664c5f/href">https://medium.com/media/b06a77e93534baf80fa14782be664c5f/href</a></iframe><p>To navigate through the tabs, use this keys combination:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9afb791e0a6668fe8220c0f3da3ae5c3/href">https://medium.com/media/9afb791e0a6668fe8220c0f3da3ae5c3/href</a></iframe><p>Now, after we’ve done with the tabs, let’s separate layout into two independent regions pressing the keys:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1ff636836916bffd0335ce65ac98b76/href">https://medium.com/media/b1ff636836916bffd0335ce65ac98b76/href</a></iframe><p>To enable a new region you should activate it by keys:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/925fecdc8a5e5455097db87de9a45a02/href">https://medium.com/media/925fecdc8a5e5455097db87de9a45a02/href</a></iframe><p>Let’s open a new application in the left region. I’ve chosen midnight commander (feel free to make your choice). Enter the command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ab683280e5f4c3c4d223dc37a9afefe/href">https://medium.com/media/2ab683280e5f4c3c4d223dc37a9afefe/href</a></iframe><p>In the right region we will open our test application. It’s a simple chat written in <a href="https://nodejs.org/">node.js</a> and <a href="http://socket.io/">socket.io</a>. I’ve taken this example from the official website socket.io and added to it some of the logging to show you that it works. Open the directory %repoName%/screen/chat-example and enter the commands:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13e166c5802182780c7c646c51c0b6a1/href">https://medium.com/media/13e166c5802182780c7c646c51c0b6a1/href</a></iframe><p>%repoName%<em> </em>— this is the directory’s name where the repository’s been cloned to.</p><p>If you’ve done everything right, you will see the next line on the screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e1bb7f994796400c4c01ed92d2e0102/href">https://medium.com/media/5e1bb7f994796400c4c01ed92d2e0102/href</a></iframe><p>It’s time to open your browser. Input the following localhost:3000 command in a new tab, type some text in the input field and press <em>“Enter”</em> button. You see? It all works and works correctly, you’ve got the same text both in the browser and in the terminal, in the region where you entered the command node index.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8S1jalZrVcj4Ev_ELvb7AA.jpeg" /></figure><p>Let’s simulate disconnection, click <em>“cross”</em> to close the terminal, but keep the browser running and type in some more messages. As you can see, the process hasn’t been interrupted completely and we can see our messages appearing on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6nVp4SbRhwTKPgKcERQ5BQ.jpeg" /></figure><p>This means that screen can save sessions and all processes launched. Ok, let’s return to our session, open terminal and enter the command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a0b2f31ad04884d22cbf465105db594/href">https://medium.com/media/5a0b2f31ad04884d22cbf465105db594/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lLKJUYOHTLkVbahuEGda8g.jpeg" /></figure><p>You’ve probably noticed right away that the original layout has changed. Not the most pleasant surprise to be fair. There are certain commands which you can use to save it. I guess I tried most of them and yet, couldn’t get it to work. It wouldn’t be perhaps such a big problem if you worked constantly only with two-three tabs, but what if you have six or nine tabs open, all sectioned both vertically and horizontally, than suddenly a connection’s gone and when it’s back, it all looks completely different? This isn’t handy of course. The only good thing is, all processes are saved.</p><p>For long I haven’t used terminal managers. Why you may ask? I simply didn’t know about them. I thought it was pretty standard to work with several putty open (Windows OS + remote connection to a server) and navigate them by pressing Alt + Tabs. That looked real chaos but I learnt to deal with it.</p><p>Speaking of the drawbacks, I need to mention that screen cannot create independent layouts for each tab. Screen also doesn’t save layouts in case of a connection’s drop. Before 4.1 version screen couldn’t support vertical separation (that one was pretty critical for me). Whenever you create a new region, you also need to create a new window (Ctrl + a, c), then shift to the needed directory, etc. To delete a region, you’d need to press one more key combination (Ctrl + a, :remove). Honestly, for me screen was a real savior, but some of its features were quite hard to customize. Even now there are certain things I’d be eager to add, but simply cannot do so due to the screen implementation.</p><p>To sum it up, in this post we’ve reviewed screen, one of the popular terminal managers open for mass use. We’ve looked at how it can be installed, configured and customized. We’ve also seen the example of how it functions. Let me remind you that to check key combinations, the functions they’re assigned to perform in screen, etc. you only need to enter the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60cfc7f15472c549c05e6a1315392a84/href">https://medium.com/media/60cfc7f15472c549c05e6a1315392a84/href</a></iframe><p>Leaping ahead, in the next articles I’m going to tell you about a more advanced terminal manager — tmux. We’ll also compare screen and tmux.</p><p>This is all for now. Thanks for your attention. Special thanks to those, who’ve read the post to the end. Meet you all again pretty soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81766a3d7fff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>