Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, December 5, 2023

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long.

mkdir long-name-of-directory 
cd long-name-of-directory

I checked what are the shourcuts for this. specially is there an one line command to both create and move in to the directory. Actually there is no one line command. But we can create one in our shell. 

If you are using bash, following function can be added

mkcd () { mkdir "$1" cd "$1" }

If you are using csh, you have to add an alias because C shell doesn't support function.
 
alias mkcd 'mkdir $PWD/\!:1;cd $PWD/\!:1'

If you are can't configure your enviorenment we can use following commands.
 
mkdir long-name-of-directory 
cd !^ 

Let me know If you have any other solutions.

Sunday, December 3, 2023

Using named pipes (FIFO) to inter process communication (IPC) in c++

 Named pipes can be used, if you need to setup a bidirectional channel between two processes.

Traditional UNIX pipe is unnamed and it lasts only during the process lifetime, where as named pipes last as long as the system is up, beyond the life of the process.

A named pipe is basically a file and converted into a FIFO using mkfifo(). 

Then processes attach to it for reading/writing purpose. After that reading and writing can be done as on a regular file in C++.

There have to be reading process "attached" for the other side of the pipe. If you try to open pipe for writing and there is no reading process, open will hang waiting for it or return -1 with errno set to ENXIO (when O_NONBLOCK flag is used)




NOTE:

Pipes are byte-oriented, not message oriented. If you want messages, there's other IPC for that (e.g., SysV message queues).

Since it is a stream of bytes we may need to establish a minimal transport protocol (for example use '\0' byte as a delimiter, Number of bytes write/read form sender/reciever)




Tuesday, June 5, 2018

How to make vim paste from (and copy to) system's clipboard?


I'm a vim user and most of the times when I'm coding I use yy or Shift + y to copy a line of string from one place and p to paste in another place in the same file.
What if we wanted to copy a string from one file to another or from another application to vim. I had stuck in this problem sometimes ago and thought this would be a nice thing to mention in my BLOG even if it is a simple thing.

Wednesday, November 25, 2015

Useful and Elegant Terminal Emulators for Linux

terminal emulator is a program that emulates a video terminal within some other display architecture. Though typically synonymous with a shell or text terminal, the term terminal covers all remote terminals, including graphical interfaces.
That is how Wikipedia  define what a terminal emulator is.
It allows the user access to a text terminal and all its applications such as command-line interfaces (CLI) and text user interface (TUI) applications. On Unix-like operating systems, it is common to have one or more terminal windows connected to the local machine.
So people use different types of Terminal Emulators according to their performances and preference of users.
Lets see some of different terminal emulators that can be used in Linux operating systems.

  1. Tilda
    Tilda is a GTK+ Terminal emulator and it is based on the VTE terminal emulator widget underlying GNOME terminal. They say that its design was inspired from consoles which was in computer games like Quake. Running Tilda can be faster than launching a new terminal with a keyboard shortcut because the program is already loaded into memory. So it can be useful to people who frequently find themselves opening and closing terminals.
    It has a nice interface with highly customization options and excellent built in color schemes.

    It is a free software licensed under the terms of the GNU general public license.

    Tilda home page

  2. Guake
    Guake is a drop-down terminal made for the GNOME desktop environment. Guake's style of window is based on an FPS game, and one of its goals is to be easy to reach.
    Guake is mostly written in python and has a little piece in C. Guake is packaged by a number of distributions, among which are Fedora, Debian, Ubuntu or ArchLinux.
    special Features
    • Multi tab.
    • Lightweight
    • Open URL to your browser
    • Save terminal content to a file
    Guake Screenshots

    Guake home page

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...