Showing posts with label aliases. Show all posts
Showing posts with label aliases. Show all posts

Thursday, 27 July 2017

Create Bash Aliases With Arguments In Ubuntu

Create Bash Aliases With Arguments In Ubuntu


The scenario here may not be the same with you but the point is you want your bash alias to work with parameters.

Say I want to display a files content in colors and I want the output to display line numbers as well.

For the color part, I used pythons syntax highlighter called pygments and I used bash built-in line numbering command called nl.

Now to achieve my goal, I have to pipe nl to the result of pygmentize:

pygmentize test.php | nl

This is quite a hassle especially if you have to do it frequently only with different files. Unfortunately, bash alias does not directly accept parameters. The solution is to create a bash function.

ccat() { pygmentize $1 | nl }

or multi-line:

function ccat() { 
pygmentize $1 | nl
}

I named the function ccat (custom cat) because it works like a cat command but the syntax is highlighted.

Put this function in ~/.bashrc and then restart your terminal or use source:

ccat test.php

{ Read More }


Thursday, 20 July 2017

Create Aliases in Windows!!

Create Aliases in Windows!!


Hey!! guys i like to share this pretty cool knowledge with you that we can also create aliases in windows as we create in linux .... in windows we call it DOS key!!

DOSKEY  (Wikipedia crap :p)

               
DOSKEY is a utility for DOS and Microsoft Windows that adds command history, macro functionality, and improved editing features to the command line interpreters COMMAND.COM and CMD.EXE. It was included as a TSR program with MS-DOS and PC DOS versions 5 and later, Windows 9x and Windows XP or later.
In early 1989 functionality similar to DOSKEY was introduced with DR-DOS 3.40 with its HISTORY CONFIG.SYS directive. This enabled a user-configurable console input history buffer and recall as well as pattern search functionality on console driver level, that is, fully integrated into the operating system and transparent to running applications. In summer 1991 DOSKEY was introduced in MS-DOS/PC DOS 5.0 in order to provide some of the same functionality. DOSKEY also added a macro expansion facility, which, however, required special support to be implemented in applications like command line processors before they can take advantage of it. Starting with Novell DOS 7 in 1993 the macro capabilities were provided by an external DOSKEY command as well. In order to also emulate DOSKEYs history buffer functionality under DR-DOS, the DR-DOS DOSKEY works as a frontend to the resident history buffer functionality, which remained part of the kernel in DR-DOS.
In current Windows NT-based operating systems DOSKEYs functionality is built into CMD.EXE, although the DOSKEY command is still used to change its operation.

Practical Work 

In this pic i wanna make a short and simple alias for sublime text as you can see i made it using the following command

doskey s1 = sublime_text.exe $* 

and thats it ... remember i have sublime_text.exe file in my environment path variable 
so now instead of typing the whole bullshit(i.e sublime_text) i just have to enter the alias that i have setted in the particular command prompt

Problem 

The main problem is that if the close the session or can say when you close the cmd you doskey setup is lost :( :(  and it will not work in other command prompt

Dont be sad i have a solution for it

Solution 

 1.) Create a new folder in the c:windows directory called bin.
 2.) Run notepad as Administrator.
 3.) Enter the following command in it

 @echo off
@doskey sl = sublime_text $*

4.) Now save the file as doskey.bat in the c:windows in folder that we actually created
5.) press control + r and run box will open
6.) type regedit in the run box and hit enter
7.) search for HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
8.) Add a new String Value called AutoRun and set the absolute path in the value of c:windows indoskey.bat.



The doskey.bat file will now be executed before opening a new cmd session which will set all of your alias ready for you to use.

Now i have alias for windows same that i used in linux environment

Thanks for giving your valueable time in reading this post
Thank you !!
{ Read More }


Sunday, 14 May 2017

Creating Bash Aliases

Creating Bash Aliases


In bash scripting, you can create aliases for the shell commands you frequently used. The most simple way to create an alias is to assign it directly in your terminal:

alias ll=ls -l


The ls command list the files and directories in the current directory.

Now if you run the ll command in your terminal, this will list the files in long format as specified by the -l option.

The disadvantage is that the alias will only work in the current shell. This means that if you open a new tab or window, the ll command will not work there. Also, the ll command will not work anymore once you closed the terminal.

If you want to create an alias that will work in any shell instance, you can add your aliases in ~/.bash_aliases.

After adding your alias fire up this command to make it effective immediately:

$ source ~/.bash_aliases

{ Read More }