Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

Thursday, May 28, 2020

Rust process to connect ssh via os command

During my rust learning, I wonder to make some application out of my learning. So, thought to make ssh based terminal application so I can use it my daily use.

As I would like to start a small piece of the snippet to make the actual logic to prototype. I began to identify the ssh frameworks that I can utilize in my application.  During that exploration time, I found a shortcut which is easy to achieve at every first level.

The idea is to use the ssh command available in the os. This code is very simple and attracts the rust beginners.

This snippet calling the ssh terminal command and passing the required argument
that is actually my username and server host.
use std::process::Command;

fn main() {
    let username = "<Fillup>";
    let hostname = "<Fillup>";
    let cmd_out = Command::new("ssh")
        .arg(format!("{}@{}",username,hostname))
        .output();

    match cmd_out {
        Ok(o) => {
            let l = format!(
                "{}{}",
                String::from_utf8_lossy(&o.stdout),
                String::from_utf8_lossy(&o.stderr)
            );
            if o.status.success() {
                println!("{}", l);
            }
        }
        Err(e) => {
            println!("{}", e);
        }
    }
}

So the question is still open, did I complete the SSH application?

Now it is in WIP, once completed let you know.

Monday, May 25, 2020

Make your Mac folder shortcuts into terminal command

Every day all you geeks are typing 'cd' command more than like any another command.
As you want to navigate to move almost nuke and corner of your file system.
But sometimes you often go to a specific folder, maybe that is Downloads or you specific workspace folder.


~ cd ~/Downloads
➜  Downloads
 
As this is very near to home folder and shot, it is easy to navigate but what if you have a project-specific folder that has a 100 character length path. Alias is useful to set shortcut command for your folders.
Edit your shell source file by doing the following command in terminal
 
vi ~/.zshrc

or
 
vi ~/.bash_profile

Update below content into the bottom of your source file,
 
#Alias to my Download folder 
alias downloads='cd ~/Downloads'

Save the profile file by doing vi save (escape + :wq!)
 
➜  downloads

Now type downloads in your terminal hit enter. You are into the Downloads folder.

Troubleshoot:
 Restart the terminal if not working, or check the typo to your profile settings

Below command can be useful to add the current directory to the alias list, as it avoids to open the
bash_profile to update in the vi editor.

 Replace the <name> with the actual value. after the edit, there should not any angle brackets in the terminal command.


➜  echo "alias <name>='cd $PWD'" | cat >> ~/.bash_profile 

Note: As this is appended command, please make sure that you execute it once per alias name.

Tuesday, December 11, 2012

Linux Error & Hot Fix

If this is your Linux terminal error
-------------------------------------------------------------------------------------------------------------------------------------
Command 'lesspipe' is available in the following places
 * /bin/lesspipe
 * /usr/bin/lesspipe
The command could not be located because '/usr/bin:/bin' is not included in the PATH environment variable.
lesspipe: command not found
Command 'dircolors' is available in '/usr/bin/dircolors'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
dircolors: command not found
Command 'uname' is available in '/bin/uname'
The command could not be located because '/bin' is not included in the PATH environment variable.
uname: command not found
bash: [: =: unary operator expected
Command 'sed' is available in '/bin/sed'
The command could not be located because '/bin' is not included in the PATH environment variable.
sed: command not found
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found

-------------------------------------------------------------------------------------------------------------------------------------

Hot Fix:
Do the following command in the same error terminal
 -------------------------------------------------------------------------------------------------------------------------------------
  export PATH=/usr/bin:/bin

Merging two sorted arrays - Big O (n+m) time complexity

 Problem :  Merge the two sorted arrays. Edge case :  Array can empty Arrays can be in different size let getMaxLength = ( input1 , input...