add bashrc script

This commit is contained in:
Maciej Lebiest 2023-03-12 13:19:38 +01:00
parent 80cb374abb
commit 7f5c8c112a
2 changed files with 111 additions and 12 deletions

View file

@ -59,28 +59,36 @@ podman run --privileged -it --rm \
-e XDG_RUNTIME_DIR=/runtime_dir \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY \
- v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions \
-v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions \
--workdir /data \
-v "./:/data:rw" \
neovim:latest
-v "$(pwd):/data:rw" \
neovim:latest
```
function for opening current dir or some files/folders in temporary container:
```bash
function nvim() {
# Mount current folder OR folders/files given as parameters, then
# open neovim. Container will be removed on neovim exit.
# Mount wayland for clipboard sync.
# Also pass all parameters to neovim as its arguments.
for arg in "$@"; do
if [ "$arg" ] && [ -f "$arg" -o -d "$arg" ] ; then
local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw"";
if [ -f "$arg" ] || [ -d "$arg" ] ; then
local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw""
echo "Mounting $arg"
fi
done
if [ -z "$MOUNT_FILE" ]; then
# mount current workdir if no arguments with path
# mount on base_path to make sessions saving work
local base_path="$(pwd)"
local base_path
base_path="$(pwd)"
local MOUNT_FOLDER="--workdir /data$base_path -v "$base_path:/data$base_path:rw""
fi
# make sure there is a folder for sessions on default path
mkdir -p ~/.local/share/nvim/sessions
podman run --privileged -it --rm \
-e XDG_RUNTIME_DIR=/runtime_dir \
@ -100,22 +108,36 @@ then use function below.
```bash
function nvim_project() {
# Mount current folder to a container that will not be removed on exit.
# Requires first argument to be a name for the container so it can be
# easily reentered later.
# If you specify some paths as latter parameters, then these paths will
# be mounted instead of current folder.
# Also mounts wayland for clipboard sync.
if [ -z "$1" ]; then
echo "give project/container name as first parameter";
return 1;
echo "give project/container name as first parameter"
return 1
fi
local container_name
container_name="$1"
shift # skip first parameter as it can be name of a folder/file in
# current dir so it could try mounting it later
for arg in "$@"; do
if [ "$arg" ] && [ -f "$arg" -o -d "$arg" ] ; then
local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw"";
if [ -f "$arg" ] || [ -d "$arg" ] ; then
local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw""
echo "Mounting $arg"
fi
done
if [ -z "$MOUNT_FILE" ]; then
# mount current workdir if no arguments with path
# mount on base_path to make sessions saving work
local base_path="$(pwd)"
local base_path
base_path="$(pwd)"
local MOUNT_FOLDER="--workdir /data$base_path -v "$base_path:/data$base_path:rw""
fi
# make sure there is a folder for sessions on default path
mkdir -p ~/.local/share/nvim/sessions
podman run --privileged -it \
-e XDG_RUNTIME_DIR=/runtime_dir \
@ -125,7 +147,7 @@ function nvim_project() {
$MOUNT_FILE \
$MOUNT_FOLDER \
--entrypoint bash \
--name "$1" \
--name $container_name \
neovim:latest
}

77
bashrc_nvim.sh Normal file
View file

@ -0,0 +1,77 @@
#!/bin/bash
function nvim() {
# Mount current folder OR folders/files given as parameters, then
# open neovim. Container will be removed on neovim exit.
# Mount wayland for clipboard sync.
# Also pass all parameters to neovim as its arguments.
for arg in "$@"; do
if [ -f "$arg" ] || [ -d "$arg" ] ; then
local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw""
echo "Mounting $arg"
fi
done
if [ -z "$MOUNT_FILE" ]; then
# mount current workdir if no arguments with path
# mount on base_path to make sessions saving work
local base_path
base_path="$(pwd)"
local MOUNT_FOLDER="--workdir /data$base_path -v "$base_path:/data$base_path:rw""
fi
# make sure there is a folder for sessions on default path
mkdir -p ~/.local/share/nvim/sessions
podman run --privileged -it --rm \
-e XDG_RUNTIME_DIR=/runtime_dir \
-e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \
-v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \
-v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \
$MOUNT_FILE \
$MOUNT_FOLDER \
neovim:latest "$@"
}
function nvim_project() {
# Mount current folder to a container that will not be removed on exit.
# Requires first argument to be a name for the container so it can be
# easily reentered later.
# If you specify some paths as latter parameters, then these paths will
# be mounted instead of current folder.
# Also mounts wayland for clipboard sync.
if [ -z "$1" ]; then
echo "give project/container name as first parameter"
return 1
fi
local container_name
container_name="$1"
shift # skip first parameter as it can be name of a folder/file in
# current dir so it could try mounting it later
for arg in "$@"; do
if [ -f "$arg" ] || [ -d "$arg" ] ; then
local MOUNT_FILE="$MOUNT_FILE -v "$arg:$arg:rw""
echo "Mounting $arg"
fi
done
if [ -z "$MOUNT_FILE" ]; then
# mount current workdir if no arguments with path
# mount on base_path to make sessions saving work
local base_path
base_path="$(pwd)"
local MOUNT_FOLDER="--workdir /data$base_path -v "$base_path:/data$base_path:rw""
fi
# make sure there is a folder for sessions on default path
mkdir -p ~/.local/share/nvim/sessions
podman run --privileged -it \
-e XDG_RUNTIME_DIR=/runtime_dir \
-e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \
-v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \
-v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \
$MOUNT_FILE \
$MOUNT_FOLDER \
--entrypoint bash \
--name $container_name \
neovim:latest
}