Tmux Scroll Up/Down Page using Ctrl-b and Ctrl-f - key-bindings

Once in scroll-mode, how do I use Ctrl+b and Ctrl+f to scroll up and down pages?
These commands currently move back and forth between characters.
.tmux.conf
set -g default-terminal "screen-256color"
setw -g xterm-keys on
set -g status-bg black
set -g status-fg white
set -g history-limit 999999999
bind C-d detach
bind r source-file ~/.tmux.conf
set -g prefix C-z
if-shell 'test "$(tmux -V)" = "tmux 1.5"' 'set -g prefix C-a,C-z'
if-shell 'test "$(tmux -V)" = "tmux 1.6"' 'set -g prefix2 C-a'
if-shell 'test "$(tmux -V)" = "tmux 1.7"' 'set -g prefix2 C-a'
unbind C-b
bind C-a send-keys C-a
bind C-z send-keys C-z
# These are available in iTerm by default, but need to be explicitly configured
# in Terminal.app.
# S-Up: ^[[1;2A
# S-Down: ^[[1;2B
# S-Right: ^[[1;2C
# S-Left: ^[[1;2D
bind -n S-Up copy-mode
bind -n S-Down command-prompt
bind -n S-Right next-window
bind -n S-Left previous-window
#set -g base-index 1
set-window-option -g mode-keys vi

Add below into .tmux.conf, you can move like in vim use hjkl, Ctrl+D/Ctrl+U(PageDown/Up) in the tmux scroll mode. Even more, you can use / to search.
setw -g mode-keys vi
set -g status-keys vi
bind-key -t vi-edit Up history-up
bind-key -t vi-edit Down history-down
Hope this will help you :)

Related

`nsenter` + specifying a user needs environment variable assignment

I'm running a command in a network namespace using nsenter, and I wish to run it as an ordinary (non-root) user because I want to access an Android SDK installation, which exists in my own home directory.
I find that although I can specify which user I want in my nsenter command, my environment variables don't get set accordingly, and I don't see a way to set those variables. What can I do?
sudo nsenter --net=/var/run/netns/netns1 -S 1000 bash -c -l whoami
# => bash: /root/.bashrc: Permission denied
# => myuser
sudo nsenter --net=/var/run/netns/netns1 -S 1000 bash -c 'echo $HOME'
# => /root
Observe that:
When I attempt a login shell (with -l), bash attempts to source /root/.bashrc instead of /home/myuser/.bashrc
$HOME is /root
If I prepend my command with a variable assignment (HOME=/home/markham sudo nsenter --net=/var/run/netns/netns1 -S 1000 bash -c -l whoami), I get the same results.
(I'm on version nsenter from util-linux 2.34.)

Dockerfile - CMD with nohup

How can I put the following into Dockerfile? I'm rebuilding a image and have modified few things.
Upon inspecting the original image, I see that it has CMD in a weird format.
"Cmd": [
"/bin/sh",
"-c",
"#(nop) CMD [\"supervisord\" \"-c\" \"/etc/supervisor.conf\"]"
],
The Entrypoint script executes this as its argument. But I'm unsure how to add this in the new Dockerfile.
I'm not sure if I can have 2 CMD and not sure how to add the nohup in a Dockerfile
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["/bin/sh", "-c", "#(nop)"]
CMD ["supervisord","-c", "/etc/supervisor.conf"]
Here is the entrypoint.sh
#!/bin/bash
set -eo pipefail
# if command starts with an option, prepend supervisord
if [ "${1:0:1}" = '-' ]; then
set -- supervisord "$#"
fi
# Add local user;
# Either use the MARADNS_USER_ID if passed in at runtime or fallback.
USER_ID=${MARADNS_USER_ID:-9001}
echo "Starting with UID : $USER_ID"
usermod -u $USER_ID maradns
# update permissions
chown -R maradns.maradns /etc/maradns
chown -R maradns.maradns /var/cache/deadwood
# replace the UID and GID of the maradns user
MARADNS_UID=`id -u maradns`
MARADNS_GID=`id -g maradns`
cp /etc/mararc.custom /etc/mararc
sed -i -r "s/(maradns_uid\s*=\s*)([0-9]+)(.*)/\1${MARADNS_UID}\3/" /etc/mararc
sed -i -r "s/(maradns_gid\s*=\s*)([0-9]+)(.*)/\1${MARADNS_GID}\3/" /etc/mararc
# bind maradns on container host
MARADNS_ADDRESS=`ifconfig eth0 | grep 'inet addr:' | cut -d ' ' -f12 | cut -d ':' -f2`
sed -i -r "s/(ipv4_bind_addresses\s*=\s*)(.*)(.*)/\1\"${MARADNS_ADDRESS}\"\3/" /etc/mararc
# copy filebeat configuration
cp /etc/filebeat/filebeat.yml.custom /etc/filebeat/filebeat.yml
# run command
exec "$#"

Programatically set a env var for each Tmux session

I am trying to set a different NVIM_LISTEN_ADDRESS for each Tmux session, so that each session can run its own Neovim server.
I have tried the following:
session=$("tmux display-message -p '#S'")
tmux set-environment -t "$session" NVIM_LISTEN_ADDRESS /tmp/"$session"
But while that then allows you to tmux show-environment NVIM_LISTEN_ADDRESS, it does not allow you to echo $NVIM_LISTEN_ADDRESS, which is what I need.
I have also tried the following in my .tmux.conf, but it does nothing:
set-option -g default-command "NVIM_LISTEN_ADDRESS=/tmp/#S reattach-to-user-namespace -l /usr/local/bin/zsh"
Also tried:
set-option -g default-command "reattach-to-user-namespace -l NVIM_LISTEN_ADDRESS=/tmp/#S /usr/local/bin/zsh"
(Previously, this was set-option -g default-command "reattach-to-user-namespace -l /usr/local/bin/zsh", which is necessary to integration the Tmux and Mac OS X clipboards.)
What should I do?
Solved -- /.zshrc:
session=$(tmux display-message -p '#S')
address="/tmp/$session"
local NVIM_LISTEN_ADDRESS="$address"

How to change locale settings on Fedora Docker container?

On a normal server e.g. a Linode VPS I would normally do:
localectl set-locale LANG=<locale>.utf8
timedatectl set-timezone <timezone>
But since systemd is not present or does not work on containers I get:
Failed to create bus connection: No such file or directory
Now, my goal is just to change these settings without using systemd but such approach seems to go undocumented. Is there a reference for non-systemd alternatives to config tools?
Some documentation about locale setting in arch wiki: https://wiki.archlinux.org/index.php/locale
In Dockerfile, adjust LANG to your desired locale. You can add more than one locale in /etc/locale.gen to have a choice later.
Works on debian, arch, but locale-gen misses on fedora:
ENV LANG=en_US.utf8
RUN echo "$LANG UTF-8" >> /etc/locale.gen
RUN locale-gen
RUN update-locale --reset LANG=$LANG
More general is localedef, works on fedora, too:
ENV LANG=en_US.UTF-8
localedef --verbose --force -i en_US -f UTF-8 en_US.UTF-8
Put this in your Dockerfile
ENV TZ=America/Denver
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Edit .bash_profile or .bashrc from root and add the following.
TZ='Asia/Kolkata'
export TZ
Save file and commit image after its done.
Based on a technique used in sti-base, I came up with the following workaround for https://github.com/ncoghlan/fedbuildenv/blob/09a18d91e7af64a45394669bac2595a4b628960d/Dockerfile#L26:
# Set a useful default locale
RUN echo "export LANG=en_US.utf-8" > /opt/export_LANG.sh
ENV BASH_ENV=/opt/export_LANG.sh \
ENV=/opt/export_LANG.sh \
PROMPT_COMMAND="source /opt/export_LANG.sh"
BASH_ENV covers non-interactive bash sessions, ENV covers sh sessions, and PROMPT_COMMAND covers interactive bash sessions.
this seems to be the debians's equivalent of locale-gen:
RUN localedef -v -c -i fr_FR -f UTF-8 fr_FR.UTF-8 || true

How to always run php in console interactively way not to exit?

I am in debian7.8+php5.3 .
root#debian:/home/debian# php -a
Interactive mode enabled
<?php
echo "hello";
?>
No reaction when to click enter ,to click ctrl+D can get the output:
hello
But it will exit from php Interactive mode into debian console.
root#debian:/home/debian#
How to always run php in console interactively way not to exit ?
You can try use phpsh - An interactive shell for php
How to install phpsh
$ sudo apt-get install python # this is necessary to run phpsh
$ cd ~/
$ wget https://github.com/facebook/phpsh/zipball/master
$ unzip phpsh-master.zip
$ cd phpsh-master
$ sudo cp -r src /etc/phpsh # phpsh seems to complain unless it resides at /etc/phpsh
$ sudo ln -s /etc/phpsh/phpsh /usr/bin/phpsh # put phpsh on the $PATH
Run phpsh
$ phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> echo 'hello world';
hello world
php>

Resources