JP Vossen on 9 Dec 2015 00:12:11 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] PLUG N 2015-12-08: QEMU, sshfs and readline


Thanks to Keith for a very interesting QEMU P2V (physical 2 virtual) talk!


We also briefly discussed SSHFS, which is very cool because it requires
*only* SSH server on the remote side.  The client/local side requires
both FUSE and SSHFS but then allows you to:

$ mkdir mountpoint
$ sshfs user@host:remotedir mountpoint
$ do.stuff
$ fusermount -u mountpoint
$ rmdir mountpoint

Now that's pretty darn awesome all by itself.  But you can also do
things like:
$ sshfs -o idmap=user -o gid=1002 user@host:remotedir mountpoint

See `man sshfs` for details, there are a bunch of useful things.  See
also https://en.wikipedia.org/wiki/SSHFS.

I've been known to do crazy things like this when comparing and/or
migrating servers that have no GUI (since servers shouldn't) when I want
to use a nice GUI tool like `meld`:
$ mkdir rserver1 rserver2
$ sshfs root@rserver1:/ rserver1
$ sshfs root@rserver2:/ rserver2
$ meld rserver1/etc/passwd rserver2/etc/passwd
...
$ fusermount -u rserver1
$ fusermount -u rserver2
$ rmdir rserver1 rserver2

Obviously, you can see how a simple bash wrapper script would make this
a lot easier...  :-)


I was also talking with Mike about `bash` tweaks, especially making tab
completion friendlier.  We also touched on `zsh`, which does have nicer
completion and some friendlier defaults.

First, make sure your system has the "bash-completion" package installed
and that you are sourcing it.  Details vary by distro, but for Mint 17 I
have the package "bash-completion-1:2.1-4ubuntu0.1" and
'/etc/bash.bashrc' sources '/etc/bash_completion'.  This adds a whole
lot of completions.

Then, you can tweak the Readline settings to change all kinds of things.
 You usually do that in '~/.inputrc' (for you) and/or '/etc/inputrc'
(system-wide), but you *can* do it from the command line or some other file.

When experimenting at the command line NOTE it is easy to screw up!!!
Run a sub-shell (just type `bash`) to experiment in.  That way you can
just exit it when you mess up.  Symptoms are usually the sudden
inability to type some literal character like "i" which turns out to be
a bit of a problem when you need the `bind` command to fix it.  (Yes,
I've done this to myself.  More than once.)

I have lots of custom settings on my machines, but I also have a sub-set
of critical, can't-live-without settings in a single file snippet that I
can easily append to '~/.bashrc' on machines I use infrequently or don't
own.

-----
####################### JP settings ##############################
# Only if interactive bash with a terminal!
[ -t 1 -a -n "$BASH_VERSION" ] && {
  PS1='\n[\u@\h:T\l:L$SHLVL:C\!:J\j:\D{%Y-%m-%d_%H:%M:%S_%Z}]\n$PWD\$ '
  alias ll='ls --color=auto -F -h -l'
  alias md='mkdir'
  alias vzip='unzip -lvM'
  export LESS='--LONG-PROMPT --LINE-NUMBERS --ignore-case --QUIET --no-init'
  bind '"\e[A": history-search-backward'
  bind '"\e[B": history-search-forward'
  bind '"\C-i": menu-complete'
  bind 'set completion-ignore-case on'
  export HISTCONTROL='erasedups:ignoredups:ignorespace'
  export HISTIGNORE='&:[ ]*'    # bash >= 3, omit dups & lines starting
with space
  export MANWIDTH=80            # man page width, use < 80 if COLUMNS=80
& less -N
  export VISUAL='vi'
  function mcd {
    mkdir -p "$1"
      cd "$1"
  }
}
-----

Most of that should be clear, but the 4 `bind` commands are really the
key in the context of the discussion with Mike.  The first two set it so
that when you type the first few characters of a commend then hit up
arrow, it will search.  E.g., type "vi " then hit up arrow for the last
`vi` command.  Keep hitting up or down arrow to scroll the list of `vi`
commands in your history.  REALLY useful, should be the default (might
be the default in zsh).

The 3rd `bind` command changes tab completion to both display all the
possible tab completion alternatives and to cycle through them at each
tab press.

The 4th one makes tab completion case insensitive.

There are LOTS more things you can tweak in Readline, check out the
docs.  And you can get the Readline docs, and a whole lot more at the
following page, which I amusingly generate using a Perl script:
	http://www.bashcookbook.com/bashinfo/
	http://www.bashcookbook.com/bashinfo/#readline

Later,
JP
--  -------------------------------------------------------------------
JP Vossen, CISSP | http://www.jpsdomain.org/ | http://bashcookbook.com/
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug