Skip to content

Commit

Permalink
Merge pull request #224 from a-kenji/config-file
Browse files Browse the repository at this point in the history
Add: Config file
  • Loading branch information
a-kenji authored Apr 5, 2021
2 parents cdbd74f + d9a85e9 commit 381b63d
Show file tree
Hide file tree
Showing 14 changed files with 914 additions and 285 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,44 @@ Zellij was initially called "Mosaic".

The status bar on the bottom should guide you through the possible keyboard shortcuts in the app.

# Configuration
It is possible to configure keyboard shortcuts and their actions in a yaml file.
An example file can be found under `example/config.yaml`.

Zellij will look for a file `/zellij/config.yaml` in the default configuration location of your os.

To pass a config file directly to zellij run it either with:
`cargo run -- config [FILE]` or `zellij config [FILE]`.

The structure is as follows:
```
keybinds:
normal:
- action: []
key: []
```
`normal` is one of the `modes` zellij can be in.
It is possible to bind a sequence of actions to numerous keys at the same time.
Here a reference to the [Key](https://docs.rs/termion/1.5.6/termion/event/enum.Key.html) format that is used.

For example:
```
keybinds:
normal:
- action: [ NewTab, GoToTab: 1,]
key: [ Char: 'c',]
```
Will create a new tab and then switch to tab number 1 on pressing the
`c` key.
Whereas:
```
keybinds:
normal:
- action: [ NewTab,]
key: [ Char: 'c', Char: 'd',]
```
Will create a new tab on pressing either the `c` or the `d` key.

# What is the current status of the project?

Zellij is in the last stages of being VT compatible. As much as modern terminals are.
Expand Down
81 changes: 79 additions & 2 deletions assets/completions/_zellij
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,93 @@ _zellij() {
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
":: :_zellij_commands" \
"*::: :->zellij" \
&& ret=0

case $state in
(zellij)
words=($line[1] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:zellij-command-$line[1]:"
case $line[1] in
(c)
_arguments "${_arguments_options[@]}" \
'--clean[Disables loading of configuration file at default location]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::path:_files' \
&& ret=0
;;
(c)
_arguments "${_arguments_options[@]}" \
'--clean[Disables loading of configuration file at default location]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::path:_files' \
&& ret=0
;;
(config)
_arguments "${_arguments_options[@]}" \
'--clean[Disables loading of configuration file at default location]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::path:_files' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
esac
;;
esac
}

(( $+functions[_zellij_commands] )) ||
_zellij_commands() {
local commands; commands=(

"config:Path to the configuration yaml file" \
"help:Prints this message or the help of the given subcommand(s)" \
)
_describe -t commands 'zellij commands' commands "$@"
}
(( $+functions[_c_commands] )) ||
_c_commands() {
local commands; commands=(

)
_describe -t commands 'c commands' commands "$@"
}
(( $+functions[_zellij__c_commands] )) ||
_zellij__c_commands() {
local commands; commands=(

)
_describe -t commands 'zellij c commands' commands "$@"
}
(( $+functions[_zellij__config_commands] )) ||
_zellij__config_commands() {
local commands; commands=(

)
_describe -t commands 'zellij config commands' commands "$@"
}
(( $+functions[_zellij__help_commands] )) ||
_zellij__help_commands() {
local commands; commands=(

)
_describe -t commands 'zellij help commands' commands "$@"
}

_zellij "$@"
56 changes: 55 additions & 1 deletion assets/completions/zellij.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ _zellij() {
cmd="zellij"
;;

c)
cmd+="__c"
;;
config)
cmd+="__config"
;;
help)
cmd+="__help"
;;
*)
;;
esac
done

case "${cmd}" in
zellij)
opts=" -m -d -h -V -s -o -l --move-focus --debug --help --version --split --open-file --max-panes --layout "
opts=" -m -d -h -V -s -o -l --move-focus --debug --help --version --split --open-file --max-panes --layout config help c c"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -63,6 +72,51 @@ _zellij() {
return 0
;;

zellij__c)
opts=" -h -V --clean --help --version <path> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
zellij__config)
opts=" -h -V --clean --help --version <path> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
zellij__help)
opts=" -h -V --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
esac
}

Expand Down
7 changes: 7 additions & 0 deletions assets/completions/zellij.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ complete -c zellij -n "__fish_use_subcommand" -s m -l move-focus -d 'Send "move
complete -c zellij -n "__fish_use_subcommand" -s d -l debug
complete -c zellij -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
complete -c zellij -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
complete -c zellij -n "__fish_use_subcommand" -f -a "config" -d 'Path to the configuration yaml file'
complete -c zellij -n "__fish_use_subcommand" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)'
complete -c zellij -n "__fish_seen_subcommand_from config" -l clean -d 'Disables loading of configuration file at default location'
complete -c zellij -n "__fish_seen_subcommand_from config" -s h -l help -d 'Prints help information'
complete -c zellij -n "__fish_seen_subcommand_from config" -s V -l version -d 'Prints version information'
complete -c zellij -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information'
complete -c zellij -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information'
26 changes: 26 additions & 0 deletions example/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
keybinds:
normal:
- action: [GoToTab: 1,]
key: [F: 1,]
- action: [GoToTab: 2,]
key: [F: 2,]
- action: [GoToTab: 3,]
key: [F: 3,]
- action: [GoToTab: 4,]
key: [F: 4,]
- action: [NewTab,]
key: [F: 5,]
- action: [MoveFocus: Left,]
key: [ Alt: h,]
- action: [MoveFocus: Right,]
key: [ Alt: l,]
- action: [MoveFocus: Down,]
key: [ Alt: j,]
- action: [MoveFocus: Up,]
key: [ Alt: k,]
pane:
- action: [ NewPane:, SwitchToMode: Normal,]
key: [Char: 'n',]
- action: [ NewPane: , ]
key: [Char: 'N',]
17 changes: 16 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(StructOpt, Debug, Default)]
#[derive(StructOpt, Default, Debug)]
#[structopt(name = "zellij")]
pub struct CliArgs {
/// Send "split (direction h == horizontal / v == vertical)" to active zellij session
Expand All @@ -24,6 +24,21 @@ pub struct CliArgs {
#[structopt(short, long)]
pub layout: Option<PathBuf>,

#[structopt(subcommand)]
pub config: Option<ConfigCli>,

#[structopt(short, long)]
pub debug: bool,
}

#[derive(Debug, StructOpt)]
pub enum ConfigCli {
/// Path to the configuration yaml file
#[structopt(alias = "c")]
Config {
path: Option<PathBuf>,
#[structopt(long)]
/// Disables loading of configuration file at default location
clean: bool,
},
}
5 changes: 3 additions & 2 deletions src/common/input/actions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Definition of the actions that can be bound to keys.

use serde::{Deserialize, Serialize};
use zellij_tile::data::InputMode;

/// The four directions (left, right, up, down).
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum Direction {
Left,
Right,
Expand All @@ -12,7 +13,7 @@ pub enum Direction {
}

/// Actions that can be bound to keys.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum Action {
/// Quit Zellij.
Quit,
Expand Down
Loading

0 comments on commit 381b63d

Please sign in to comment.