Migrate to chezmoi
Move config files from config to chezmoi Add script to auto install packages with DNF and Cargo
This commit is contained in:
parent
110e0882c6
commit
224c7ed45c
1654 changed files with 470035 additions and 51 deletions
46
chezmoi/dot_config/tmux/plugins/tmux-fzf/Anti-996-LICENSE
Normal file
46
chezmoi/dot_config/tmux/plugins/tmux-fzf/Anti-996-LICENSE
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
Copyright (c) 2019 Sainnhepark
|
||||
|
||||
Anti 996 License Version 1.0 (Draft)
|
||||
|
||||
Permission is hereby granted to any individual or legal entity
|
||||
obtaining a copy of this licensed work (including the source code,
|
||||
documentation and/or related items, hereinafter collectively referred
|
||||
to as the "licensed work"), free of charge, to deal with the licensed
|
||||
work for any purpose, including without limitation, the rights to use,
|
||||
reproduce, modify, prepare derivative works of, distribute, publish
|
||||
and sublicense the licensed work, subject to the following conditions:
|
||||
|
||||
1. The individual or the legal entity must conspicuously display,
|
||||
without modification, this License and the notice on each redistributed
|
||||
or derivative copy of the Licensed Work.
|
||||
|
||||
2. The individual or the legal entity must strictly comply with all
|
||||
applicable laws, regulations, rules and standards of the jurisdiction
|
||||
relating to labor and employment where the individual is physically
|
||||
located or where the individual was born or naturalized; or where the
|
||||
legal entity is registered or is operating (whichever is stricter). In
|
||||
case that the jurisdiction has no such laws, regulations, rules and
|
||||
standards or its laws, regulations, rules and standards are
|
||||
unenforceable, the individual or the legal entity are required to
|
||||
comply with Core International Labor Standards.
|
||||
|
||||
3. The individual or the legal entity shall not induce or force its
|
||||
employee(s), whether full-time or part-time, or its independent
|
||||
contractor(s), in any methods, to agree in oral or written form, to
|
||||
directly or indirectly restrict, weaken or relinquish his or her
|
||||
rights or remedies under such laws, regulations, rules and standards
|
||||
relating to labor and employment as mentioned above, no matter whether
|
||||
such written or oral agreement are enforceable under the laws of the
|
||||
said jurisdiction, nor shall such individual or the legal entity
|
||||
limit, in any methods, the rights of its employee(s) or independent
|
||||
contractor(s) from reporting or complaining to the copyright holder or
|
||||
relevant authorities monitoring the compliance of the license about
|
||||
its violation(s) of the said license.
|
||||
|
||||
THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN ANY WAY CONNECTION WITH THE
|
||||
LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK.
|
||||
21
chezmoi/dot_config/tmux/plugins/tmux-fzf/LICENSE
Normal file
21
chezmoi/dot_config/tmux/plugins/tmux-fzf/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Sainnhepark
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
190
chezmoi/dot_config/tmux/plugins/tmux-fzf/README.md
Normal file
190
chezmoi/dot_config/tmux/plugins/tmux-fzf/README.md
Normal file
|
|
@ -0,0 +1,190 @@
|
|||

|
||||
|
||||
# Features
|
||||
|
||||
- Manage sessions (switch, new, rename, detach, kill).
|
||||
- Manage windows (switch, link, move, swap, rename, kill).
|
||||
- Manage panes (switch, break, join, swap, layout, kill, resize, rename).
|
||||
- Search commands and append to command prompt.
|
||||
- Search key bindings and execute.
|
||||
- Search clipboard history and paste to current window.
|
||||
- Process management (top, pstree, terminate, kill, interrupt, continue, stop, quit, hangup).
|
||||
- User menu (run custom commands).
|
||||
- Preview sessions, windows and panes.
|
||||
- Multiple selection.
|
||||
|
||||
# Installation
|
||||
|
||||
## Requirements
|
||||
|
||||
- [GNU bash](https://www.gnu.org/software/bash/)
|
||||
- [sed](https://www.gnu.org/software/sed/)
|
||||
- [junegunn/fzf](https://github.com/junegunn/fzf/)
|
||||
- [CopyQ](https://github.com/hluk/CopyQ/) (optional): Access system clipboard, fallback to builtin tmux buffers if copyq is not executable.
|
||||
- [pstree](https://gitlab.com/psmisc/psmisc/) (optional): Display process tree.
|
||||
|
||||
**Note:** Please use this command to check whether tmux is able to find fzf [#1](https://github.com/sainnhe/tmux-fzf/issues/1): `tmux run-shell -b 'command -v fzf'`
|
||||
|
||||
## Install via [TPM](https://github.com/tmux-plugins/tpm/)
|
||||
|
||||
Add this line to your `~/.tmux.conf`
|
||||
|
||||
```tmux
|
||||
set -g @plugin 'sainnhe/tmux-fzf'
|
||||
```
|
||||
|
||||
Reload configuration, then press `prefix` + `I`.
|
||||
|
||||
# Usage
|
||||
|
||||
To launch tmux-fzf, press `prefix` + `F` (Shift+F).
|
||||
|
||||
This plugin supports multiple selection for some actions, you can press `TAB` and `Shift-TAB` to mark multiple items.
|
||||
|
||||
Most of the features work out of the box, but there are some features that need to be explained here.
|
||||
|
||||
## Kill Window(s)
|
||||
|
||||
The `kill` action in tmux-fzf actually uses `tmux unlink-window -k` instead of `tmux kill-window`.
|
||||
|
||||
The main difference between `unlink-window -k` and `kill-window` is that `kill-window` will kill current window and all other windows linked to it, while `unlink-window -k` will only kill current window.
|
||||
|
||||
The logic of `unlink -k` is a bit like hard links. If the current window only exists in one session, then kill; if the current window exists in multiple sessions, then unlink.
|
||||
|
||||
Btw, if you want to bind a key to kill current window, I would recommend `unlink-window -k` instead of `kill`.
|
||||
|
||||
## User Menu
|
||||
|
||||
You can add a custom menu to quickly execute some commands.
|
||||
|
||||
This feature is not enabled by default. To enable it, add something like this to `~/.tmux.conf`
|
||||
|
||||
```tmux
|
||||
TMUX_FZF_MENU=\
|
||||
"foo\necho 'Hello!'\n"\
|
||||
"bar\nls ~\n"\
|
||||
"sh\nsh ~/test.sh\n"
|
||||
```
|
||||
|
||||
When you launch tmux-fzf, an extra item named `menu` will appear. Selecting this item will produce [this](https://user-images.githubusercontent.com/37491630/66251156-71836000-e73c-11e9-809d-e865651f8d7d.png).
|
||||
|
||||
There will be 3 items to select from: `foo`, `bar` and `sh`.
|
||||
|
||||
When you select `foo`, tmux will execute `echo 'Hello!'`.
|
||||
|
||||
When you select `bar`, tmux will execute `ls ~`.
|
||||
|
||||
When you select `sh`, tmux will execute `sh ~/test.sh`.
|
||||
|
||||
**Note:**
|
||||
|
||||
- `foo` and `echo 'hello'` are separated by `\n` in `TMUX_FZF_MENU`, and you need to add another `\n` after `echo 'hello'`.
|
||||
- **DO NOT** add additional white spaces/tabs at the beginning of each line.
|
||||
- Commands are executed using `tmux -c`, so please make sure `tmux -c "your command"` does work.
|
||||
|
||||
## Popup Window
|
||||
|
||||
Popup window is a new feature introduced in tmux 3.2 . To enable this feature, you'll need to have tmux >= 3.2 installed.
|
||||
|
||||
This feature is automatically enabled in tmux >= 3.2, but you can disable it using `$TMUX_FZF_OPTIONS`, see [Fzf Behavior](#fzf-behavior).
|
||||
|
||||
# Customization
|
||||
|
||||
## Key Binding
|
||||
|
||||
For example, to use `prefix` + `C-f` (Ctrl+F), add this line to your `~/.tmux.conf`
|
||||
|
||||
```tmux
|
||||
TMUX_FZF_LAUNCH_KEY="C-f"
|
||||
```
|
||||
|
||||
## Fzf Behavior
|
||||
|
||||
This plugin will read [fzf environment variables](https://github.com/junegunn/fzf/#environment-variables), so you can use these variables to customize the behavior of fzf (e.g. prompt and color).
|
||||
|
||||
In addition, this plugin supports customizing the options of `fzf-tmux` command which is [bundled with fzf](https://github.com/junegunn/fzf#fzf-tmux-script), you can customize them by adding something like this to `~/.tmux.conf`
|
||||
|
||||
```tmux
|
||||
# Default value in tmux < 3.2
|
||||
TMUX_FZF_OPTIONS="-m"
|
||||
|
||||
# Default value in tmux >= 3.2
|
||||
TMUX_FZF_OPTIONS="-p -w 62% -h 38% -m"
|
||||
```
|
||||
|
||||
To list all available options of `fzf-tmux`, execute `~/.tmux/plugins/tmux-fzf/scripts/.fzf-tmux --help` in your shell.
|
||||
|
||||
## Preview
|
||||
|
||||
Preview is enabled by default. To hide it, add something like this to your `~/.tmux.conf`:
|
||||
|
||||
```tmux
|
||||
TMUX_FZF_PREVIEW=0
|
||||
```
|
||||
|
||||
Then the preview window will be hidden until `toggle-preview` is triggered.
|
||||
|
||||
## Order
|
||||
|
||||
To customize the order of the actions, add something like this to your `~/.tmux.conf`:
|
||||
|
||||
```tmux
|
||||
TMUX_FZF_ORDER="session|window|pane|command|keybinding|clipboard|process"
|
||||
```
|
||||
|
||||
You can also use this variable to disable unwanted features. For example, to disable `clipboard` and `process`, simply delete them in `$TMUX_FZF_ORDER`:
|
||||
|
||||
```tmux
|
||||
TMUX_FZF_ORDER="session|window|pane|command|keybinding"
|
||||
```
|
||||
|
||||
## Format
|
||||
|
||||
For some reasons, you may want to customize format of panes, windows, sessions listed in fzf. There are three variables to complete this work:
|
||||
|
||||
`TMUX_FZF_PANE_FORMAT` `TMUX_FZF_WINDOW_FORMAT` `TMUX_FZF_SESSION_FORMAT`
|
||||
|
||||
For example, `tmux list-panes -a` doesn't show running program and window name by default. If you want to show running program and window name, add something like this to `~/.tmux.conf`
|
||||
|
||||
```tmux
|
||||
TMUX_FZF_PANE_FORMAT="[#{window_name}] #{pane_current_command} [#{pane_width}x#{pane_height}] [history #{history_size}/#{history_limit}, #{history_bytes} bytes] #{?pane_active,[active],[inactive]}"
|
||||
```
|
||||
|
||||
Similarly, `TMUX_FZF_WINDOW_FORMAT` and `TMUX_FZF_SESSION_FORMAT` can also be handled in this way.
|
||||
|
||||
For more information, check "FORMATS" section in tmux manual.
|
||||
|
||||
|
||||
## Filter
|
||||
|
||||
When using the window listing script, it is possible to filter its output. This relies on the tmux filtering feature with a specific syntax for filters. For more information about this feature, check "FORMATS" section in the tmux manual.
|
||||
|
||||
To use this filtering feature, set the variable `TMUX_FZF_WINDOW_FILTER` to the filter you want to apply before calling the `window.sh` script.
|
||||
|
||||
# FAQ
|
||||
|
||||
**Q: Why use environment variables instead of tmux options to customize this plugin?**
|
||||
|
||||
**A:** Because the performance of tmux options is very bad. I pushed a branch named `tmux-options` to demonstrate how bad the performance will be if we use tmux options to customize this plugin, you can checkout this branch and get it a try.
|
||||
|
||||
**Q: How to launch tmux-fzf with preselected action?**
|
||||
|
||||
**A:** See [#6](https://github.com/sainnhe/tmux-fzf/issues/6).
|
||||
|
||||
**Q: What's your status line configuration?**
|
||||
|
||||
**A:** See this [post](https://www.sainnhe.dev/post/status-line-config/).
|
||||
|
||||
**Q: What's the color scheme used in the screenshot?**
|
||||
|
||||
**A:** [Gruvbox Material](https://github.com/sainnhe/gruvbox-material)
|
||||
|
||||
# More plugins
|
||||
|
||||
- [sainnhe/tmux-translator](https://github.com/sainnhe/tmux-translator): A translation plugin powered by popup window.
|
||||
|
||||
# License
|
||||
|
||||
The code of [/scripts/.fzf-tmux](./scripts/.fzf-tmux) is copied from [junegunn/fzf](https://github.com/junegunn/fzf#license) which is licensed under [MIT](https://github.com/junegunn/fzf/blob/master/LICENSE).
|
||||
|
||||
Other code is distributed under [MIT](./LICENSE) && [Anti-996](./Anti-996-LICENSE).
|
||||
1
chezmoi/dot_config/tmux/plugins/tmux-fzf/dot_git/HEAD
Normal file
1
chezmoi/dot_config/tmux/plugins/tmux-fzf/dot_git/HEAD
Normal file
|
|
@ -0,0 +1 @@
|
|||
ref: refs/heads/master
|
||||
13
chezmoi/dot_config/tmux/plugins/tmux-fzf/dot_git/config
Normal file
13
chezmoi/dot_config/tmux/plugins/tmux-fzf/dot_git/config
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
[submodule]
|
||||
active = .
|
||||
[remote "origin"]
|
||||
url = https://git::@github.com/sainnhe/tmux-fzf
|
||||
fetch = +refs/heads/master:refs/remotes/origin/master
|
||||
[branch "master"]
|
||||
remote = origin
|
||||
merge = refs/heads/master
|
||||
|
|
@ -0,0 +1 @@
|
|||
Unnamed repository; edit this file 'description' to name the repository.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message taken by
|
||||
# applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit. The hook is
|
||||
# allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "applypatch-msg".
|
||||
|
||||
. git-sh-setup
|
||||
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
|
||||
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
|
||||
:
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message.
|
||||
# Called by "git commit" with one argument, the name of the file
|
||||
# that has the commit message. The hook should exit with non-zero
|
||||
# status after issuing an appropriate message if it wants to stop the
|
||||
# commit. The hook is allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "commit-msg".
|
||||
|
||||
# Uncomment the below to add a Signed-off-by line to the message.
|
||||
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
|
||||
# hook is more suited to it.
|
||||
#
|
||||
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
||||
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
|
||||
|
||||
# This example catches duplicate Signed-off-by lines.
|
||||
|
||||
test "" = "$(grep '^Signed-off-by: ' "$1" |
|
||||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
||||
echo >&2 Duplicate Signed-off-by lines.
|
||||
exit 1
|
||||
}
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use IPC::Open2;
|
||||
|
||||
# An example hook script to integrate Watchman
|
||||
# (https://facebook.github.io/watchman/) with git to speed up detecting
|
||||
# new and modified files.
|
||||
#
|
||||
# The hook is passed a version (currently 2) and last update token
|
||||
# formatted as a string and outputs to stdout a new update token and
|
||||
# all files that have been modified since the update token. Paths must
|
||||
# be relative to the root of the working tree and separated by a single NUL.
|
||||
#
|
||||
# To enable this hook, rename this file to "query-watchman" and set
|
||||
# 'git config core.fsmonitor .git/hooks/query-watchman'
|
||||
#
|
||||
my ($version, $last_update_token) = @ARGV;
|
||||
|
||||
# Uncomment for debugging
|
||||
# print STDERR "$0 $version $last_update_token\n";
|
||||
|
||||
# Check the hook interface version
|
||||
if ($version ne 2) {
|
||||
die "Unsupported query-fsmonitor hook version '$version'.\n" .
|
||||
"Falling back to scanning...\n";
|
||||
}
|
||||
|
||||
my $git_work_tree = get_working_dir();
|
||||
|
||||
my $retry = 1;
|
||||
|
||||
my $json_pkg;
|
||||
eval {
|
||||
require JSON::XS;
|
||||
$json_pkg = "JSON::XS";
|
||||
1;
|
||||
} or do {
|
||||
require JSON::PP;
|
||||
$json_pkg = "JSON::PP";
|
||||
};
|
||||
|
||||
launch_watchman();
|
||||
|
||||
sub launch_watchman {
|
||||
my $o = watchman_query();
|
||||
if (is_work_tree_watched($o)) {
|
||||
output_result($o->{clock}, @{$o->{files}});
|
||||
}
|
||||
}
|
||||
|
||||
sub output_result {
|
||||
my ($clockid, @files) = @_;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# binmode $fh, ":utf8";
|
||||
# print $fh "$clockid\n@files\n";
|
||||
# close $fh;
|
||||
|
||||
binmode STDOUT, ":utf8";
|
||||
print $clockid;
|
||||
print "\0";
|
||||
local $, = "\0";
|
||||
print @files;
|
||||
}
|
||||
|
||||
sub watchman_clock {
|
||||
my $response = qx/watchman clock "$git_work_tree"/;
|
||||
die "Failed to get clock id on '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub watchman_query {
|
||||
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
|
||||
or die "open2() failed: $!\n" .
|
||||
"Falling back to scanning...\n";
|
||||
|
||||
# In the query expression below we're asking for names of files that
|
||||
# changed since $last_update_token but not from the .git folder.
|
||||
#
|
||||
# To accomplish this, we're using the "since" generator to use the
|
||||
# recency index to select candidate nodes and "fields" to limit the
|
||||
# output to file names only. Then we're using the "expression" term to
|
||||
# further constrain the results.
|
||||
my $last_update_line = "";
|
||||
if (substr($last_update_token, 0, 1) eq "c") {
|
||||
$last_update_token = "\"$last_update_token\"";
|
||||
$last_update_line = qq[\n"since": $last_update_token,];
|
||||
}
|
||||
my $query = <<" END";
|
||||
["query", "$git_work_tree", {$last_update_line
|
||||
"fields": ["name"],
|
||||
"expression": ["not", ["dirname", ".git"]]
|
||||
}]
|
||||
END
|
||||
|
||||
# Uncomment for debugging the watchman query
|
||||
# open (my $fh, ">", ".git/watchman-query.json");
|
||||
# print $fh $query;
|
||||
# close $fh;
|
||||
|
||||
print CHLD_IN $query;
|
||||
close CHLD_IN;
|
||||
my $response = do {local $/; <CHLD_OUT>};
|
||||
|
||||
# Uncomment for debugging the watch response
|
||||
# open ($fh, ">", ".git/watchman-response.json");
|
||||
# print $fh $response;
|
||||
# close $fh;
|
||||
|
||||
die "Watchman: command returned no output.\n" .
|
||||
"Falling back to scanning...\n" if $response eq "";
|
||||
die "Watchman: command returned invalid output: $response\n" .
|
||||
"Falling back to scanning...\n" unless $response =~ /^\{/;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub is_work_tree_watched {
|
||||
my ($output) = @_;
|
||||
my $error = $output->{error};
|
||||
if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {
|
||||
$retry--;
|
||||
my $response = qx/watchman watch "$git_work_tree"/;
|
||||
die "Failed to make watchman watch '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
$output = $json_pkg->new->utf8->decode($response);
|
||||
$error = $output->{error};
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# close $fh;
|
||||
|
||||
# Watchman will always return all files on the first query so
|
||||
# return the fast "everything is dirty" flag to git and do the
|
||||
# Watchman query just to get it over with now so we won't pay
|
||||
# the cost in git to look up each individual file.
|
||||
my $o = watchman_clock();
|
||||
$error = $output->{error};
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
output_result($o->{clock}, ("/"));
|
||||
$last_update_token = $o->{clock};
|
||||
|
||||
eval { launch_watchman() };
|
||||
return 0;
|
||||
}
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub get_working_dir {
|
||||
my $working_dir;
|
||||
if ($^O =~ 'msys' || $^O =~ 'cygwin') {
|
||||
$working_dir = Win32::GetCwd();
|
||||
$working_dir =~ tr/\\/\//;
|
||||
} else {
|
||||
require Cwd;
|
||||
$working_dir = Cwd::cwd();
|
||||
}
|
||||
|
||||
return $working_dir;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to prepare a packed repository for use over
|
||||
# dumb transports.
|
||||
#
|
||||
# To enable this hook, rename this file to "post-update".
|
||||
|
||||
exec git update-server-info
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed
|
||||
# by applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-applypatch".
|
||||
|
||||
. git-sh-setup
|
||||
precommit="$(git rev-parse --git-path hooks/pre-commit)"
|
||||
test -x "$precommit" && exec "$precommit" ${1+"$@"}
|
||||
:
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git commit" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message if
|
||||
# it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-commit".
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=$(git hash-object -t tree /dev/null)
|
||||
fi
|
||||
|
||||
# If you want to allow non-ASCII filenames set this variable to true.
|
||||
allownonascii=$(git config --type=bool hooks.allownonascii)
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
||||
# them from being added to the repository. We exploit the fact that the
|
||||
# printable range starts at the space character and ends with tilde.
|
||||
if [ "$allownonascii" != "true" ] &&
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||
then
|
||||
cat <<\EOF
|
||||
Error: Attempt to add a non-ASCII file name.
|
||||
|
||||
This can cause problems if you want to work with people on other platforms.
|
||||
|
||||
To be portable it is advisable to rename the file.
|
||||
|
||||
If you know what you are doing you can disable this check using:
|
||||
|
||||
git config hooks.allownonascii true
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If there are whitespace errors, print the offending file names and fail.
|
||||
exec git diff-index --check --cached $against --
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git merge" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message to
|
||||
# stderr if it wants to stop the merge commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-merge-commit".
|
||||
|
||||
. git-sh-setup
|
||||
test -x "$GIT_DIR/hooks/pre-commit" &&
|
||||
exec "$GIT_DIR/hooks/pre-commit"
|
||||
:
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/sh
|
||||
|
||||
# An example hook script to verify what is about to be pushed. Called by "git
|
||||
# push" after it has checked the remote status, but before anything has been
|
||||
# pushed. If this script exits with a non-zero status nothing will be pushed.
|
||||
#
|
||||
# This hook is called with the following parameters:
|
||||
#
|
||||
# $1 -- Name of the remote to which the push is being done
|
||||
# $2 -- URL to which the push is being done
|
||||
#
|
||||
# If pushing without using a named remote those arguments will be equal.
|
||||
#
|
||||
# Information about the commits which are being pushed is supplied as lines to
|
||||
# the standard input in the form:
|
||||
#
|
||||
# <local ref> <local oid> <remote ref> <remote oid>
|
||||
#
|
||||
# This sample shows how to prevent push of commits where the log message starts
|
||||
# with "WIP" (work in progress).
|
||||
|
||||
remote="$1"
|
||||
url="$2"
|
||||
|
||||
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
||||
|
||||
while read local_ref local_oid remote_ref remote_oid
|
||||
do
|
||||
if test "$local_oid" = "$zero"
|
||||
then
|
||||
# Handle delete
|
||||
:
|
||||
else
|
||||
if test "$remote_oid" = "$zero"
|
||||
then
|
||||
# New branch, examine all commits
|
||||
range="$local_oid"
|
||||
else
|
||||
# Update to existing branch, examine new commits
|
||||
range="$remote_oid..$local_oid"
|
||||
fi
|
||||
|
||||
# Check for WIP commit
|
||||
commit=$(git rev-list -n 1 --grep '^WIP' "$range")
|
||||
if test -n "$commit"
|
||||
then
|
||||
echo >&2 "Found WIP commit in $local_ref, not pushing"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# Copyright (c) 2006, 2008 Junio C Hamano
|
||||
#
|
||||
# The "pre-rebase" hook is run just before "git rebase" starts doing
|
||||
# its job, and can prevent the command from running by exiting with
|
||||
# non-zero status.
|
||||
#
|
||||
# The hook is called with the following parameters:
|
||||
#
|
||||
# $1 -- the upstream the series was forked from.
|
||||
# $2 -- the branch being rebased (or empty when rebasing the current branch).
|
||||
#
|
||||
# This sample shows how to prevent topic branches that are already
|
||||
# merged to 'next' branch from getting rebased, because allowing it
|
||||
# would result in rebasing already published history.
|
||||
|
||||
publish=next
|
||||
basebranch="$1"
|
||||
if test "$#" = 2
|
||||
then
|
||||
topic="refs/heads/$2"
|
||||
else
|
||||
topic=`git symbolic-ref HEAD` ||
|
||||
exit 0 ;# we do not interrupt rebasing detached HEAD
|
||||
fi
|
||||
|
||||
case "$topic" in
|
||||
refs/heads/??/*)
|
||||
;;
|
||||
*)
|
||||
exit 0 ;# we do not interrupt others.
|
||||
;;
|
||||
esac
|
||||
|
||||
# Now we are dealing with a topic branch being rebased
|
||||
# on top of master. Is it OK to rebase it?
|
||||
|
||||
# Does the topic really exist?
|
||||
git show-ref -q "$topic" || {
|
||||
echo >&2 "No such branch $topic"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Is topic fully merged to master?
|
||||
not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
|
||||
if test -z "$not_in_master"
|
||||
then
|
||||
echo >&2 "$topic is fully merged to master; better remove it."
|
||||
exit 1 ;# we could allow it, but there is no point.
|
||||
fi
|
||||
|
||||
# Is topic ever merged to next? If so you should not be rebasing it.
|
||||
only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
|
||||
only_next_2=`git rev-list ^master ${publish} | sort`
|
||||
if test "$only_next_1" = "$only_next_2"
|
||||
then
|
||||
not_in_topic=`git rev-list "^$topic" master`
|
||||
if test -z "$not_in_topic"
|
||||
then
|
||||
echo >&2 "$topic is already up to date with master"
|
||||
exit 1 ;# we could allow it, but there is no point.
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
|
||||
/usr/bin/perl -e '
|
||||
my $topic = $ARGV[0];
|
||||
my $msg = "* $topic has commits already merged to public branch:\n";
|
||||
my (%not_in_next) = map {
|
||||
/^([0-9a-f]+) /;
|
||||
($1 => 1);
|
||||
} split(/\n/, $ARGV[1]);
|
||||
for my $elem (map {
|
||||
/^([0-9a-f]+) (.*)$/;
|
||||
[$1 => $2];
|
||||
} split(/\n/, $ARGV[2])) {
|
||||
if (!exists $not_in_next{$elem->[0]}) {
|
||||
if ($msg) {
|
||||
print STDERR $msg;
|
||||
undef $msg;
|
||||
}
|
||||
print STDERR " $elem->[1]\n";
|
||||
}
|
||||
}
|
||||
' "$topic" "$not_in_next" "$not_in_master"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
<<\DOC_END
|
||||
|
||||
This sample hook safeguards topic branches that have been
|
||||
published from being rewound.
|
||||
|
||||
The workflow assumed here is:
|
||||
|
||||
* Once a topic branch forks from "master", "master" is never
|
||||
merged into it again (either directly or indirectly).
|
||||
|
||||
* Once a topic branch is fully cooked and merged into "master",
|
||||
it is deleted. If you need to build on top of it to correct
|
||||
earlier mistakes, a new topic branch is created by forking at
|
||||
the tip of the "master". This is not strictly necessary, but
|
||||
it makes it easier to keep your history simple.
|
||||
|
||||
* Whenever you need to test or publish your changes to topic
|
||||
branches, merge them into "next" branch.
|
||||
|
||||
The script, being an example, hardcodes the publish branch name
|
||||
to be "next", but it is trivial to make it configurable via
|
||||
$GIT_DIR/config mechanism.
|
||||
|
||||
With this workflow, you would want to know:
|
||||
|
||||
(1) ... if a topic branch has ever been merged to "next". Young
|
||||
topic branches can have stupid mistakes you would rather
|
||||
clean up before publishing, and things that have not been
|
||||
merged into other branches can be easily rebased without
|
||||
affecting other people. But once it is published, you would
|
||||
not want to rewind it.
|
||||
|
||||
(2) ... if a topic branch has been fully merged to "master".
|
||||
Then you can delete it. More importantly, you should not
|
||||
build on top of it -- other people may already want to
|
||||
change things related to the topic as patches against your
|
||||
"master", so if you need further changes, it is better to
|
||||
fork the topic (perhaps with the same name) afresh from the
|
||||
tip of "master".
|
||||
|
||||
Let's look at this example:
|
||||
|
||||
o---o---o---o---o---o---o---o---o---o "next"
|
||||
/ / / /
|
||||
/ a---a---b A / /
|
||||
/ / / /
|
||||
/ / c---c---c---c B /
|
||||
/ / / \ /
|
||||
/ / / b---b C \ /
|
||||
/ / / / \ /
|
||||
---o---o---o---o---o---o---o---o---o---o---o "master"
|
||||
|
||||
|
||||
A, B and C are topic branches.
|
||||
|
||||
* A has one fix since it was merged up to "next".
|
||||
|
||||
* B has finished. It has been fully merged up to "master" and "next",
|
||||
and is ready to be deleted.
|
||||
|
||||
* C has not merged to "next" at all.
|
||||
|
||||
We would want to allow C to be rebased, refuse A, and encourage
|
||||
B to be deleted.
|
||||
|
||||
To compute (1):
|
||||
|
||||
git rev-list ^master ^topic next
|
||||
git rev-list ^master next
|
||||
|
||||
if these match, topic has not merged in next at all.
|
||||
|
||||
To compute (2):
|
||||
|
||||
git rev-list master..topic
|
||||
|
||||
if this is empty, it is fully merged to "master".
|
||||
|
||||
DOC_END
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to make use of push options.
|
||||
# The example simply echoes all push options that start with 'echoback='
|
||||
# and rejects all pushes when the "reject" push option is used.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-receive".
|
||||
|
||||
if test -n "$GIT_PUSH_OPTION_COUNT"
|
||||
then
|
||||
i=0
|
||||
while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"
|
||||
do
|
||||
eval "value=\$GIT_PUSH_OPTION_$i"
|
||||
case "$value" in
|
||||
echoback=*)
|
||||
echo "echo from the pre-receive-hook: ${value#*=}" >&2
|
||||
;;
|
||||
reject)
|
||||
exit 1
|
||||
esac
|
||||
i=$((i + 1))
|
||||
done
|
||||
fi
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to prepare the commit log message.
|
||||
# Called by "git commit" with the name of the file that has the
|
||||
# commit message, followed by the description of the commit
|
||||
# message's source. The hook's purpose is to edit the commit
|
||||
# message file. If the hook fails with a non-zero status,
|
||||
# the commit is aborted.
|
||||
#
|
||||
# To enable this hook, rename this file to "prepare-commit-msg".
|
||||
|
||||
# This hook includes three examples. The first one removes the
|
||||
# "# Please enter the commit message..." help message.
|
||||
#
|
||||
# The second includes the output of "git diff --name-status -r"
|
||||
# into the message, just before the "git status" output. It is
|
||||
# commented because it doesn't cope with --amend or with squashed
|
||||
# commits.
|
||||
#
|
||||
# The third example adds a Signed-off-by line to the message, that can
|
||||
# still be edited. This is rarely a good idea.
|
||||
|
||||
COMMIT_MSG_FILE=$1
|
||||
COMMIT_SOURCE=$2
|
||||
SHA1=$3
|
||||
|
||||
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
|
||||
|
||||
# case "$COMMIT_SOURCE,$SHA1" in
|
||||
# ,|template,)
|
||||
# /usr/bin/perl -i.bak -pe '
|
||||
# print "\n" . `git diff --cached --name-status -r`
|
||||
# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
|
||||
# *) ;;
|
||||
# esac
|
||||
|
||||
# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
||||
# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
|
||||
# if test -z "$COMMIT_SOURCE"
|
||||
# then
|
||||
# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
|
||||
# fi
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/sh
|
||||
|
||||
# An example hook script to update a checked-out tree on a git push.
|
||||
#
|
||||
# This hook is invoked by git-receive-pack(1) when it reacts to git
|
||||
# push and updates reference(s) in its repository, and when the push
|
||||
# tries to update the branch that is currently checked out and the
|
||||
# receive.denyCurrentBranch configuration variable is set to
|
||||
# updateInstead.
|
||||
#
|
||||
# By default, such a push is refused if the working tree and the index
|
||||
# of the remote repository has any difference from the currently
|
||||
# checked out commit; when both the working tree and the index match
|
||||
# the current commit, they are updated to match the newly pushed tip
|
||||
# of the branch. This hook is to be used to override the default
|
||||
# behaviour; however the code below reimplements the default behaviour
|
||||
# as a starting point for convenient modification.
|
||||
#
|
||||
# The hook receives the commit with which the tip of the current
|
||||
# branch is going to be updated:
|
||||
commit=$1
|
||||
|
||||
# It can exit with a non-zero status to refuse the push (when it does
|
||||
# so, it must not modify the index or the working tree).
|
||||
die () {
|
||||
echo >&2 "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Or it can make any necessary changes to the working tree and to the
|
||||
# index to bring them to the desired state when the tip of the current
|
||||
# branch is updated to the new commit, and exit with a zero status.
|
||||
#
|
||||
# For example, the hook can simply run git read-tree -u -m HEAD "$1"
|
||||
# in order to emulate git fetch that is run in the reverse direction
|
||||
# with git push, as the two-tree form of git read-tree -u -m is
|
||||
# essentially the same as git switch or git checkout that switches
|
||||
# branches while keeping the local changes in the working tree that do
|
||||
# not interfere with the difference between the branches.
|
||||
|
||||
# The below is a more-or-less exact translation to shell of the C code
|
||||
# for the default behaviour for git's push-to-checkout hook defined in
|
||||
# the push_to_deploy() function in builtin/receive-pack.c.
|
||||
#
|
||||
# Note that the hook will be executed from the repository directory,
|
||||
# not from the working tree, so if you want to perform operations on
|
||||
# the working tree, you will have to adapt your code accordingly, e.g.
|
||||
# by adding "cd .." or using relative paths.
|
||||
|
||||
if ! git update-index -q --ignore-submodules --refresh
|
||||
then
|
||||
die "Up-to-date check failed"
|
||||
fi
|
||||
|
||||
if ! git diff-files --quiet --ignore-submodules --
|
||||
then
|
||||
die "Working directory has unstaged changes"
|
||||
fi
|
||||
|
||||
# This is a rough translation of:
|
||||
#
|
||||
# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX
|
||||
if git cat-file -e HEAD 2>/dev/null
|
||||
then
|
||||
head=HEAD
|
||||
else
|
||||
head=$(git hash-object -t tree --stdin </dev/null)
|
||||
fi
|
||||
|
||||
if ! git diff-index --quiet --cached --ignore-submodules $head --
|
||||
then
|
||||
die "Working directory has staged changes"
|
||||
fi
|
||||
|
||||
if ! git read-tree -u -m "$commit"
|
||||
then
|
||||
die "Could not update working tree to new HEAD"
|
||||
fi
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/sh
|
||||
|
||||
# An example hook script to validate a patch (and/or patch series) before
|
||||
# sending it via email.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an appropriate
|
||||
# message if it wants to prevent the email(s) from being sent.
|
||||
#
|
||||
# To enable this hook, rename this file to "sendemail-validate".
|
||||
#
|
||||
# By default, it will only check that the patch(es) can be applied on top of
|
||||
# the default upstream branch without conflicts in a secondary worktree. After
|
||||
# validation (successful or not) of the last patch of a series, the worktree
|
||||
# will be deleted.
|
||||
#
|
||||
# The following config variables can be set to change the default remote and
|
||||
# remote ref that are used to apply the patches against:
|
||||
#
|
||||
# sendemail.validateRemote (default: origin)
|
||||
# sendemail.validateRemoteRef (default: HEAD)
|
||||
#
|
||||
# Replace the TODO placeholders with appropriate checks according to your
|
||||
# needs.
|
||||
|
||||
validate_cover_letter () {
|
||||
file="$1"
|
||||
# TODO: Replace with appropriate checks (e.g. spell checking).
|
||||
true
|
||||
}
|
||||
|
||||
validate_patch () {
|
||||
file="$1"
|
||||
# Ensure that the patch applies without conflicts.
|
||||
git am -3 "$file" || return
|
||||
# TODO: Replace with appropriate checks for this patch
|
||||
# (e.g. checkpatch.pl).
|
||||
true
|
||||
}
|
||||
|
||||
validate_series () {
|
||||
# TODO: Replace with appropriate checks for the whole series
|
||||
# (e.g. quick build, coding style checks, etc.).
|
||||
true
|
||||
}
|
||||
|
||||
# main -------------------------------------------------------------------------
|
||||
|
||||
if test "$GIT_SENDEMAIL_FILE_COUNTER" = 1
|
||||
then
|
||||
remote=$(git config --default origin --get sendemail.validateRemote) &&
|
||||
ref=$(git config --default HEAD --get sendemail.validateRemoteRef) &&
|
||||
worktree=$(mktemp --tmpdir -d sendemail-validate.XXXXXXX) &&
|
||||
git worktree add -fd --checkout "$worktree" "refs/remotes/$remote/$ref" &&
|
||||
git config --replace-all sendemail.validateWorktree "$worktree"
|
||||
else
|
||||
worktree=$(git config --get sendemail.validateWorktree)
|
||||
fi || {
|
||||
echo "sendemail-validate: error: failed to prepare worktree" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
unset GIT_DIR GIT_WORK_TREE
|
||||
cd "$worktree" &&
|
||||
|
||||
if grep -q "^diff --git " "$1"
|
||||
then
|
||||
validate_patch "$1"
|
||||
else
|
||||
validate_cover_letter "$1"
|
||||
fi &&
|
||||
|
||||
if test "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL"
|
||||
then
|
||||
git config --unset-all sendemail.validateWorktree &&
|
||||
trap 'git worktree remove -ff "$worktree"' EXIT &&
|
||||
validate_series
|
||||
fi
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
#!/usr/bin/sh
|
||||
#
|
||||
# An example hook script to block unannotated tags from entering.
|
||||
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
|
||||
#
|
||||
# To enable this hook, rename this file to "update".
|
||||
#
|
||||
# Config
|
||||
# ------
|
||||
# hooks.allowunannotated
|
||||
# This boolean sets whether unannotated tags will be allowed into the
|
||||
# repository. By default they won't be.
|
||||
# hooks.allowdeletetag
|
||||
# This boolean sets whether deleting tags will be allowed in the
|
||||
# repository. By default they won't be.
|
||||
# hooks.allowmodifytag
|
||||
# This boolean sets whether a tag may be modified after creation. By default
|
||||
# it won't be.
|
||||
# hooks.allowdeletebranch
|
||||
# This boolean sets whether deleting branches will be allowed in the
|
||||
# repository. By default they won't be.
|
||||
# hooks.denycreatebranch
|
||||
# This boolean sets whether remotely creating branches will be denied
|
||||
# in the repository. By default this is allowed.
|
||||
#
|
||||
|
||||
# --- Command line
|
||||
refname="$1"
|
||||
oldrev="$2"
|
||||
newrev="$3"
|
||||
|
||||
# --- Safety check
|
||||
if [ -z "$GIT_DIR" ]; then
|
||||
echo "Don't run this script from the command line." >&2
|
||||
echo " (if you want, you could supply GIT_DIR then run" >&2
|
||||
echo " $0 <ref> <oldrev> <newrev>)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
|
||||
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- Config
|
||||
allowunannotated=$(git config --type=bool hooks.allowunannotated)
|
||||
allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)
|
||||
denycreatebranch=$(git config --type=bool hooks.denycreatebranch)
|
||||
allowdeletetag=$(git config --type=bool hooks.allowdeletetag)
|
||||
allowmodifytag=$(git config --type=bool hooks.allowmodifytag)
|
||||
|
||||
# check for no description
|
||||
projectdesc=$(sed -e '1q' "$GIT_DIR/description")
|
||||
case "$projectdesc" in
|
||||
"Unnamed repository"* | "")
|
||||
echo "*** Project description file hasn't been set" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Check types
|
||||
# if $newrev is 0000...0000, it's a commit to delete a ref.
|
||||
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
||||
if [ "$newrev" = "$zero" ]; then
|
||||
newrev_type=delete
|
||||
else
|
||||
newrev_type=$(git cat-file -t $newrev)
|
||||
fi
|
||||
|
||||
case "$refname","$newrev_type" in
|
||||
refs/tags/*,commit)
|
||||
# un-annotated tag
|
||||
short_refname=${refname##refs/tags/}
|
||||
if [ "$allowunannotated" != "true" ]; then
|
||||
echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
|
||||
echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/tags/*,delete)
|
||||
# delete tag
|
||||
if [ "$allowdeletetag" != "true" ]; then
|
||||
echo "*** Deleting a tag is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/tags/*,tag)
|
||||
# annotated tag
|
||||
if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
|
||||
then
|
||||
echo "*** Tag '$refname' already exists." >&2
|
||||
echo "*** Modifying a tag is not allowed in this repository." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/heads/*,commit)
|
||||
# branch
|
||||
if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
|
||||
echo "*** Creating a branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/heads/*,delete)
|
||||
# delete branch
|
||||
if [ "$allowdeletebranch" != "true" ]; then
|
||||
echo "*** Deleting a branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/remotes/*,commit)
|
||||
# tracking branch
|
||||
;;
|
||||
refs/remotes/*,delete)
|
||||
# delete tracking branch
|
||||
if [ "$allowdeletebranch" != "true" ]; then
|
||||
echo "*** Deleting a tracking branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# Anything else (is there anything else?)
|
||||
echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Finished
|
||||
exit 0
|
||||
BIN
chezmoi/dot_config/tmux/plugins/tmux-fzf/dot_git/index
Normal file
BIN
chezmoi/dot_config/tmux/plugins/tmux-fzf/dot_git/index
Normal file
Binary file not shown.
|
|
@ -0,0 +1,6 @@
|
|||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
|
|
@ -0,0 +1 @@
|
|||
0000000000000000000000000000000000000000 d62b6865c0e7c956ad1f0396823a6f34cf7452a7 aleidk <ale.navarro.parra@gmail.com> 1699105326 -0300 clone: from https://github.com/sainnhe/tmux-fzf
|
||||
|
|
@ -0,0 +1 @@
|
|||
0000000000000000000000000000000000000000 d62b6865c0e7c956ad1f0396823a6f34cf7452a7 aleidk <ale.navarro.parra@gmail.com> 1699105326 -0300 clone: from https://github.com/sainnhe/tmux-fzf
|
||||
|
|
@ -0,0 +1 @@
|
|||
0000000000000000000000000000000000000000 d62b6865c0e7c956ad1f0396823a6f34cf7452a7 aleidk <ale.navarro.parra@gmail.com> 1699105326 -0300 clone: from https://github.com/sainnhe/tmux-fzf
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,2 @@
|
|||
# pack-refs with: peeled fully-peeled sorted
|
||||
d62b6865c0e7c956ad1f0396823a6f34cf7452a7 refs/remotes/origin/master
|
||||
|
|
@ -0,0 +1 @@
|
|||
d62b6865c0e7c956ad1f0396823a6f34cf7452a7
|
||||
|
|
@ -0,0 +1 @@
|
|||
ref: refs/remotes/origin/master
|
||||
20
chezmoi/dot_config/tmux/plugins/tmux-fzf/executable_main.sh
Normal file
20
chezmoi/dot_config/tmux/plugins/tmux-fzf/executable_main.sh
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
[[ -z "$TMUX_FZF_ORDER" ]] && TMUX_FZF_ORDER="copy-mode|session|window|pane|command|keybinding|clipboard|process"
|
||||
source "$CURRENT_DIR/scripts/.envs"
|
||||
|
||||
# remove copy-mode from options if we aren't in copy-mode
|
||||
if [[ "$TMUX_FZF_ORDER" == *"copy-mode"* ]] && [ "$(tmux display-message -p '#{pane_in_mode}')" -eq 0 ]; then
|
||||
TMUX_FZF_ORDER="$(echo $TMUX_FZF_ORDER | sed -E 's/\|?copy-mode\|?//')"
|
||||
fi
|
||||
|
||||
items_origin="$(echo $TMUX_FZF_ORDER | tr '|' '\n')"
|
||||
if [[ -z "$TMUX_FZF_MENU" ]]; then
|
||||
item=$(printf "%s\n[cancel]" "$items_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
item=$(printf "menu\n%s\n[cancel]" "$items_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
fi
|
||||
[[ "$item" == "[cancel]" || -z "$item" ]] && exit
|
||||
item=$(echo "$CURRENT_DIR/scripts/$item" | sed -E 's/$/.sh/')
|
||||
tmux run-shell -b "$item"
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
if [ -x "$(command -v copyq)" ]; then
|
||||
copyq &>/dev/null &
|
||||
fi
|
||||
|
||||
[ -z "$TMUX_FZF_LAUNCH_KEY" ] && TMUX_FZF_LAUNCH_KEY="F"
|
||||
tmux bind-key "$TMUX_FZF_LAUNCH_KEY" run-shell -b "$CURRENT_DIR/main.sh"
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select clipboard history. Press TAB to mark multiple items.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
if ! [ -x "$(command -v copyq)" ]; then
|
||||
action="buffer"
|
||||
elif [ -z "$1" ]; then
|
||||
action="system"
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
if [[ "$action" == "system" ]]; then
|
||||
item_numbers=$(copyq count)
|
||||
contents="[cancel]\n"
|
||||
index=0
|
||||
while [ "$index" -lt "$item_numbers" ]; do
|
||||
_content="$(copyq read ${index} | tr '\n' ' ' | tr '\\n' ' ')"
|
||||
contents="${contents}copy${index}: ${_content}\n"
|
||||
index=$((index + 1))
|
||||
done
|
||||
copyq_index=$(printf "$contents" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS --preview=\"echo {} | sed -e 's/^copy//' -e 's/: .*//' | xargs -I{} copyq read {}\"" | sed -e 's/^copy//' -e 's/: .*//')
|
||||
[[ "$copyq_index" == "[cancel]" || -z "$copyq_index" ]] && exit
|
||||
echo "$copyq_index" | xargs -I{} sh -c 'tmux set-buffer -b _temp_tmux_fzf "$(copyq read {})" && tmux paste-buffer -b _temp_tmux_fzf && tmux delete-buffer -b _temp_tmux_fzf'
|
||||
elif [[ "$action" == "buffer" ]]; then
|
||||
selected_buffer=$(tmux list-buffers | sed -e 's/:.*bytes//' -e '1s/^/[cancel]\n/' -e 's/: "/: /' -e 's/"$//' | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS --preview=\"echo {} | sed -e 's/\[cancel\]//' -e 's/:.*$//' | head -1 | xargs tmux show-buffer -b\"" | sed 's/:.*$//')
|
||||
[[ "$selected_buffer" == "[cancel]" || -z "$selected_buffer" ]] && exit
|
||||
echo "$selected_buffer" | xargs -I{} sh -c 'tmux paste-buffer -b {}'
|
||||
fi
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a command.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
target_origin=$(tmux list-commands)
|
||||
target=$(printf "[cancel]\n%s" "$target_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS" | grep -o '^[^[:blank:]]*')
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
tmux command-prompt -I "$target"
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
copy_mode_commands="append-selection Append the selected buffer to the clipboard
|
||||
append-selection-and-cancel Append the selected buffer to the clipboard and cancel the current command
|
||||
back-to-indentation Move the cursor back to the indentation
|
||||
begin-selection Begin selection in the buffer
|
||||
bottom-line Move to the bottom line of the buffer
|
||||
cancel Cancel the current command
|
||||
clear-selection Clear the current selection in the buffer
|
||||
copy-end-of-line [<prefix>] Copy from the cursor position to the end of the line. If no prefix is given, it copies to the clipboard
|
||||
copy-end-of-line-and-cancel [<prefix>] Copy from the cursor position to the end of the line and cancel the current command
|
||||
copy-pipe-end-of-line [<command>] [<prefix>] This is equivalent to the copy-end-of-line method, but allows running a shell command on the text, and then copies it to the clipboard
|
||||
copy-line [<prefix>] Copy the entire line irrespective of the cursor position. If no prefix is given, it copies to the clipboard
|
||||
copy-line-and-cancel [<prefix>] Copy the entire line and cancel the current command
|
||||
copy-selection [<prefix>] This is equivalent to the window_copy_copy_selection method. It simply copies the selected text to the clipboard without any additional processing
|
||||
copy-selection-and-cancel [<prefix>] Copy the current selection and cancel the current command
|
||||
cursor-down Move the cursor down
|
||||
cursor-left Move the cursor left
|
||||
cursor-right Move the cursor right
|
||||
cursor-up Move the cursor up
|
||||
end-of-line Move the cursor to the end of the line
|
||||
goto-line <line> Go to the specific line
|
||||
history-bottom Scroll to the bottom of the history
|
||||
history-top Scroll to the top of the history
|
||||
jump-again Repeat the last jump
|
||||
jump-backward <to> Jump backwards to the specified text
|
||||
jump-forward <to> Jump forward to the specified text
|
||||
jump-to-mark Jump to the last mark
|
||||
middle-line Move to the middle line of the buffer
|
||||
next-matching-bracket Move to the next matching bracket
|
||||
next-paragraph Move to the next paragraph
|
||||
next-word Move to the next word
|
||||
page-down Scroll down by one page
|
||||
page-up Scroll up by one page
|
||||
previous-matching-bracket Move to the previous matching bracket
|
||||
previous-paragraph Move to the previous paragraph
|
||||
previous-word Move to the previous word
|
||||
rectangle-toggle Toggle rectangle selection mode
|
||||
refresh-from-pane Refresh the screen based on the current pane
|
||||
search-again Repeat the last search
|
||||
search-backward <for> Search backwards for the specified text
|
||||
search-forward <for> Search forward for the specified text
|
||||
select-line Select the current line
|
||||
select-word Select the current word
|
||||
start-of-line Move the cursor to the start of the line
|
||||
top-line Move to the top line of the buffer"
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a copy-mode command.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
target=$(printf "[cancel]\n%s" "$copy_mode_commands" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS" | grep -o '^[^[:blank:]]*')
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
tmux send-keys -X "$target"
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
compare_float() {
|
||||
if [ ${1%.*} -eq ${2%.*} ] && [ ${1#*.} \> ${2#*.} ] || [ ${1%.*} -gt ${2%.*} ]; then
|
||||
echo ">"
|
||||
else
|
||||
echo "<="
|
||||
fi
|
||||
}
|
||||
|
||||
# $TMUX_FZF_PREVIEW_OPTIONS
|
||||
fzf_version=$(fzf --version)
|
||||
fzf_version_1=$(echo "$fzf_version" | grep -o '^[[:digit:]]*\.[[:digit:]]*')
|
||||
fzf_version_2=$(echo "$fzf_version" | grep -o '^[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*' | sed 's/[[:digit:]]*\.//')
|
||||
if [ $(compare_float $fzf_version_1 "0.24") == ">" ] ||
|
||||
[ $fzf_version_1 == "0.24" ] &&
|
||||
[ $(compare_float $fzf_version_2 "24.3") == ">" ]; then
|
||||
fzf_preview_window_follow=":follow" # :follow option is only available in fzf >= 0.24.4
|
||||
fi
|
||||
TMUX_FZF_PREVIEW="${TMUX_FZF_PREVIEW:-1}"
|
||||
if [ "$TMUX_FZF_PREVIEW" == 1 ]; then
|
||||
TMUX_FZF_PREVIEW_OPTIONS="--preview='$current_dir/.preview {}' --preview-window=$fzf_preview_window_follow"
|
||||
else
|
||||
TMUX_FZF_PREVIEW_OPTIONS="--preview='$current_dir/.preview {}' --preview-window=${fzf_preview_window_follow}:hidden"
|
||||
fi
|
||||
|
||||
# $TMUX_FZF_BIN
|
||||
TMUX_FZF_BIN="$current_dir/.fzf-tmux"
|
||||
|
||||
# $TMUX_FZF_OPTIONS
|
||||
tmux_version=$(tmux -V | grep -oE '[0-9]+\.[0-9]*')
|
||||
if [ $(compare_float $tmux_version "3.1") == ">" ]; then
|
||||
[ -z "$TMUX_FZF_OPTIONS" ] && TMUX_FZF_OPTIONS="-p -w 62% -h 38% -m"
|
||||
else
|
||||
[ -z "$TMUX_FZF_OPTIONS" ] && TMUX_FZF_OPTIONS="-m"
|
||||
fi
|
||||
|
||||
# Unset temporary variables and functions.
|
||||
unset \
|
||||
current_dir \
|
||||
compare_float \
|
||||
fzf_version \
|
||||
fzf_version_1 \
|
||||
fzf_version_2 \
|
||||
fzf_preview_window_follow \
|
||||
tmux_version
|
||||
|
|
@ -0,0 +1,229 @@
|
|||
#!/usr/bin/env bash
|
||||
# fzf-tmux: starts fzf in a tmux pane
|
||||
# usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS]
|
||||
|
||||
fail() {
|
||||
>&2 echo "$1"
|
||||
exit 2
|
||||
}
|
||||
|
||||
fzf="$(command -v fzf 2> /dev/null)" || fzf="$(dirname "$0")/fzf"
|
||||
[[ -x "$fzf" ]] || fail 'fzf executable not found'
|
||||
|
||||
args=()
|
||||
opt=""
|
||||
skip=""
|
||||
swap=""
|
||||
close=""
|
||||
term=""
|
||||
[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}")
|
||||
[[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}")
|
||||
|
||||
help() {
|
||||
>&2 echo 'usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS]
|
||||
|
||||
LAYOUT OPTIONS:
|
||||
(default layout: -d 50%)
|
||||
|
||||
Popup window (requires tmux 3.2 or above):
|
||||
-p [WIDTH[%][,HEIGHT[%]]] (default: 50%)
|
||||
-w WIDTH[%]
|
||||
-h HEIGHT[%]
|
||||
-x COL
|
||||
-y ROW
|
||||
|
||||
Split pane:
|
||||
-u [HEIGHT[%]] Split above (up)
|
||||
-d [HEIGHT[%]] Split below (down)
|
||||
-l [WIDTH[%]] Split left
|
||||
-r [WIDTH[%]] Split right
|
||||
'
|
||||
exit
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
arg="$1"
|
||||
shift
|
||||
[[ -z "$skip" ]] && case "$arg" in
|
||||
-)
|
||||
term=1
|
||||
;;
|
||||
--help)
|
||||
help
|
||||
;;
|
||||
--version)
|
||||
echo "fzf-tmux (with fzf $("$fzf" --version))"
|
||||
exit
|
||||
;;
|
||||
-p*|-w*|-h*|-x*|-y*|-d*|-u*|-r*|-l*)
|
||||
if [[ "$arg" =~ ^-[pwhxy] ]]; then
|
||||
[[ "$opt" =~ "-E" ]] || opt="-E"
|
||||
elif [[ "$arg" =~ ^.[lr] ]]; then
|
||||
opt="-h"
|
||||
if [[ "$arg" =~ ^.l ]]; then
|
||||
opt="$opt -d"
|
||||
swap="; swap-pane -D ; select-pane -L"
|
||||
close="; tmux swap-pane -D"
|
||||
fi
|
||||
else
|
||||
opt=""
|
||||
if [[ "$arg" =~ ^.u ]]; then
|
||||
opt="$opt -d"
|
||||
swap="; swap-pane -D ; select-pane -U"
|
||||
close="; tmux swap-pane -D"
|
||||
fi
|
||||
fi
|
||||
if [[ ${#arg} -gt 2 ]]; then
|
||||
size="${arg:2}"
|
||||
else
|
||||
if [[ "$1" =~ ^[0-9%,]+$ ]] || [[ "$1" =~ ^[A-Z]$ ]]; then
|
||||
size="$1"
|
||||
shift
|
||||
else
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$arg" =~ ^-p ]]; then
|
||||
if [[ -n "$size" ]]; then
|
||||
w=${size%%,*}
|
||||
h=${size##*,}
|
||||
opt="$opt -w$w -h$h"
|
||||
fi
|
||||
elif [[ "$arg" =~ ^-[whxy] ]]; then
|
||||
opt="$opt ${arg:0:2}$size"
|
||||
elif [[ "$size" =~ %$ ]]; then
|
||||
size=${size:0:((${#size}-1))}
|
||||
if [[ -n "$swap" ]]; then
|
||||
opt="$opt -p $(( 100 - size ))"
|
||||
else
|
||||
opt="$opt -p $size"
|
||||
fi
|
||||
else
|
||||
if [[ -n "$swap" ]]; then
|
||||
if [[ "$arg" =~ ^.l ]]; then
|
||||
max=$columns
|
||||
else
|
||||
max=$lines
|
||||
fi
|
||||
size=$(( max - size ))
|
||||
[[ $size -lt 0 ]] && size=0
|
||||
opt="$opt -l $size"
|
||||
else
|
||||
opt="$opt -l $size"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
--)
|
||||
# "--" can be used to separate fzf-tmux options from fzf options to
|
||||
# avoid conflicts
|
||||
skip=1
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
args+=("$arg")
|
||||
;;
|
||||
esac
|
||||
[[ -n "$skip" ]] && args+=("$arg")
|
||||
done
|
||||
|
||||
if [[ -z "$TMUX" ]]; then
|
||||
"$fzf" "${args[@]}"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# --height option is not allowed. CTRL-Z is also disabled.
|
||||
args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore")
|
||||
|
||||
# Handle zoomed tmux pane without popup options by moving it to a temp window
|
||||
if [[ ! "$opt" =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then
|
||||
zoomed_without_popup=1
|
||||
original_window=$(tmux display-message -p "#{window_id}")
|
||||
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
|
||||
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
# Clean up named pipes on exit
|
||||
id=$RANDOM
|
||||
argsf="${TMPDIR:-/tmp}/fzf-args-$id"
|
||||
fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"
|
||||
fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
|
||||
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
|
||||
tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') )
|
||||
cleanup() {
|
||||
\rm -f $argsf $fifo1 $fifo2 $fifo3
|
||||
|
||||
# Restore tmux window options
|
||||
if [[ "${#tmux_win_opts[@]}" -gt 0 ]]; then
|
||||
eval "tmux ${tmux_win_opts[*]}"
|
||||
fi
|
||||
|
||||
# Remove temp window if we were zoomed without popup options
|
||||
if [[ -n "$zoomed_without_popup" ]]; then
|
||||
tmux display-message -p "#{window_id}" > /dev/null
|
||||
tmux swap-pane -t $original_window \; \
|
||||
select-window -t $original_window \; \
|
||||
kill-window -t $tmp_window \; \
|
||||
resize-pane -Z
|
||||
fi
|
||||
|
||||
if [[ $# -gt 0 ]]; then
|
||||
trap - EXIT
|
||||
exit 130
|
||||
fi
|
||||
}
|
||||
trap 'cleanup 1' SIGUSR1
|
||||
trap 'cleanup' EXIT
|
||||
|
||||
envs="export TERM=$TERM "
|
||||
if [[ "$opt" =~ "-E" ]]; then
|
||||
FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS"
|
||||
tmux_verson=$(tmux -V)
|
||||
if [[ ! $tmux_verson =~ 3\.2 ]]; then
|
||||
FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS"
|
||||
opt="-B $opt"
|
||||
fi
|
||||
fi
|
||||
[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
||||
[[ -n "$FZF_DEFAULT_COMMAND" ]] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"
|
||||
echo "$envs;" > "$argsf"
|
||||
|
||||
# Build arguments to fzf
|
||||
opts=$(printf "%q " "${args[@]}")
|
||||
|
||||
pppid=$$
|
||||
echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" >> $argsf
|
||||
close="; trap - EXIT SIGINT SIGTERM $close"
|
||||
|
||||
export TMUX=$(cut -d , -f 1,2 <<< "$TMUX")
|
||||
mkfifo -m o+w $fifo2
|
||||
if [[ "$opt" =~ "-E" ]]; then
|
||||
cat $fifo2 &
|
||||
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||
cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf
|
||||
else
|
||||
mkfifo $fifo1
|
||||
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> $argsf
|
||||
cat <&0 > $fifo1 &
|
||||
fi
|
||||
|
||||
tmux popup -d "$PWD" $opt "bash $argsf" > /dev/null 2>&1
|
||||
exit $?
|
||||
fi
|
||||
|
||||
mkfifo -m o+w $fifo3
|
||||
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
||||
else
|
||||
mkfifo $fifo1
|
||||
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
||||
cat <&0 > $fifo1 &
|
||||
fi
|
||||
tmux set-window-option synchronize-panes off \;\
|
||||
set-window-option remain-on-exit off \;\
|
||||
split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \
|
||||
> /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }
|
||||
cat $fifo2
|
||||
exit "$(cat $fifo3)"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
[ "$1" != '[cancel]' ] && [ "$1" != '[current]' ] && echo $1 | sed 's/: .*$//' | xargs -I{} tmux capture-pane -ep -t {}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a key binding.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
target=$(tmux list-keys | sed '1s/^/[cancel]\n/' | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
if [[ -n $(echo "$target" | grep -o "copy-mode") && -z $(echo "$target" | grep -o "prefix") ]]; then
|
||||
tmux copy-mode
|
||||
echo "$target" | sed -E 's/^.{46}//g' | xargs tmux
|
||||
else
|
||||
echo "$target" | sed -E 's/^.{46}//g' | xargs tmux
|
||||
fi
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
# get front end list
|
||||
tmux_fzf_menu_origin=$TMUX_FZF_MENU
|
||||
front_end_list=$(echo -e "$tmux_fzf_menu_origin" | sed -n '1p')
|
||||
tmux_fzf_menu_origin=$(echo -e "$tmux_fzf_menu_origin" | sed '1,2d')
|
||||
while [[ $(echo -e "$tmux_fzf_menu_origin" | wc -l | xargs) != "0" && $(echo -e "$tmux_fzf_menu_origin" | wc -l | xargs) != "1" ]]; do
|
||||
front_end_list="$front_end_list\n"$(echo -e "$tmux_fzf_menu_origin" | sed -n '1p')
|
||||
tmux_fzf_menu_origin=$(echo -e "$tmux_fzf_menu_origin" | sed '1,2d')
|
||||
done
|
||||
front_end_list=$(echo -e "$front_end_list" | sed '/^[[:space:]]*$/d')
|
||||
|
||||
target=$(printf "%s\n[cancel]" "$front_end_list" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
# get the next line in $TMUX_FZF_MENU and execute
|
||||
echo -e "$TMUX_FZF_MENU" | sed -n "/$target/{n;p;}" | xargs -I{} tmux -c {}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
current_pane_origin=$(tmux display-message -p '#S:#{window_index}.#{pane_index}: #{window_name}')
|
||||
current_pane=$(tmux display-message -p '#S:#{window_index}.#{pane_index}')
|
||||
|
||||
if [[ -z "$TMUX_FZF_PANE_FORMAT" ]]; then
|
||||
panes=$(tmux list-panes -a -F "#S:#{window_index}.#{pane_index}: [#{window_name}:#{pane_title}] #{pane_current_command} [#{pane_width}x#{pane_height}] [history #{history_size}/#{history_limit}, #{history_bytes} bytes] #{?pane_active,[active],[inactive]}")
|
||||
else
|
||||
panes=$(tmux list-panes -a -F "#S:#{window_index}.#{pane_index}: $TMUX_FZF_PANE_FORMAT")
|
||||
fi
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
if [[ -z "$1" ]]; then
|
||||
action=$(printf "switch\nbreak\njoin\nswap\nlayout\nkill\nresize\nrename\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
if [[ "$action" == "layout" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a layout.'"
|
||||
target_origin=$(printf "even-horizontal\neven-vertical\nmain-horizontal\nmain-vertical\ntiled\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
tmux select-layout "$target_origin"
|
||||
elif [[ "$action" == "resize" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select direction.'"
|
||||
target_origin=$(printf "left\nright\nup\ndown\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
if [[ "$target_origin" == "left" || "$target_origin" == "right" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Cells to be adjusted.'"
|
||||
size=$(printf "1\n2\n3\n5\n10\n20\n30\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$size" == "[cancel]" || -z "$size" ]] && exit
|
||||
if [[ "$target_origin" == "left" ]]; then
|
||||
tmux resize-pane -L "$size"
|
||||
else
|
||||
tmux resize-pane -R "$size"
|
||||
fi
|
||||
elif [[ "$target_origin" == "up" || "$target_origin" == "down" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Lines to be adjusted.'"
|
||||
size=$(printf "1\n2\n3\n5\n10\n15\n20\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$size" == "[cancel]" || -z "$size" ]] && exit
|
||||
if [[ "$target_origin" == "up" ]]; then
|
||||
tmux resize-pane -U "$size"
|
||||
else
|
||||
tmux resize-pane -D "$size"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [[ "$action" == "join" || "$action" == "kill" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target pane(s). Press TAB to mark multiple items.'"
|
||||
else
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target pane.'"
|
||||
fi
|
||||
if [[ "$action" == "switch" || "$action" == "join" ]]; then
|
||||
panes=$(echo "$panes" | grep -v "^$current_pane")
|
||||
target_origin=$(printf "%s\n[cancel]" "$panes" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
else
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$panes" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_pane_origin/")
|
||||
fi
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
target=$(echo "$target_origin" | sed 's/: .*//')
|
||||
if [[ "$action" == "switch" ]]; then
|
||||
echo "$target" | sed -E 's/:.*//g' | xargs -I{} tmux switch-client -t {}
|
||||
echo "$target" | sed -E 's/\..*//g' | xargs -I{} tmux select-window -t {}
|
||||
echo "$target" | xargs -I{} tmux select-pane -t {}
|
||||
elif [[ "$action" == "kill" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux kill-pane -t {}
|
||||
elif [[ "$action" == "swap" ]]; then
|
||||
panes=$(echo "$panes" | grep -v "^$target")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select another target pane.'"
|
||||
target_swap_origin=$(printf "%s\n[cancel]" "$panes" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$target_swap_origin" == "[cancel]" || -z "$target_swap_origin" ]] && exit
|
||||
target_swap=$(echo "$target_swap_origin" | sed 's/: .*//')
|
||||
tmux swap-pane -s "$target" -t "$target_swap"
|
||||
elif [[ "$action" == "join" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux move-pane -s {}
|
||||
elif [[ "$action" == "break" ]]; then
|
||||
cur_ses=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
|
||||
last_win_num=$(tmux list-windows | sort -nr | head -1 | sed 's/:.*//')
|
||||
((last_win_num_after = last_win_num + 1))
|
||||
tmux break-pane -s "$target" -t "$cur_ses":"$last_win_num_after"
|
||||
elif [[ "$action" == "rename" ]]; then
|
||||
tmux command-prompt -I "select-pane -t ${target} -T "
|
||||
fi
|
||||
fi
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
if [[ -z "$1" ]]; then
|
||||
if [ -x "$(command -v pstree)" ]; then
|
||||
action=$(printf "display\ntree\nterminate\nkill\ninterrupt\ncontinue\nstop\nquit\nhangup\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action=$(printf "display\nterminate\nkill\ninterrupt\ncontinue\nstop\nquit\nhangup\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
fi
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
|
||||
content_raw="$(ps aux)"
|
||||
header=$(echo "$content_raw" | head -n 1)
|
||||
content=$(echo "$content_raw" | sed 1d)
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='$header'"
|
||||
ps_selected=$(printf "[cancel]\n$content" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$ps_selected" == "[cancel]" || -z "$ps_selected" ]] && exit
|
||||
pid=$(echo "$ps_selected" | awk -F ' ' '{print $2}')
|
||||
user=$(echo "$ps_selected" | awk -F ' ' '{print $1}')
|
||||
_kill() { #{{{ _kill SIG PID USER
|
||||
if [[ "$3" == "$(whoami)" ]]; then
|
||||
kill -s $1 $2
|
||||
else
|
||||
if [ -x "$(command -v sudo)" ]; then
|
||||
tmux split-window -v -p 30 -b -c '#{pane_current_path}' "bash -c 'sudo kill -s $1 $2'"
|
||||
elif [ -x "$(command -v doas)" ]; then
|
||||
tmux split-window -v -p 30 -b -c '#{pane_current_path}' "bash -c 'doas kill -s $1 $2'"
|
||||
fi
|
||||
fi
|
||||
} #}}}
|
||||
if [[ "$action" == "display" ]]; then
|
||||
if [[ "$(uname)" == "Linux" ]]; then
|
||||
tmux split-window -v -p 50 -b -c '#{pane_current_path}' "top -p $pid"
|
||||
else
|
||||
tmux split-window -v -p 50 -b -c '#{pane_current_path}' "top -pid $pid"
|
||||
fi
|
||||
elif [[ "$action" == "tree" ]]; then
|
||||
pstree -p "$pid"
|
||||
elif [[ "$action" == "terminate" ]]; then
|
||||
_kill TERM $pid $user
|
||||
elif [[ "$action" == "kill" ]]; then
|
||||
_kill KILL $pid $user
|
||||
elif [[ "$action" == "interrupt" ]]; then
|
||||
_kill INT $pid $user
|
||||
elif [[ "$action" == "continue" ]]; then
|
||||
_kill CONT $pid $user
|
||||
elif [[ "$action" == "stop" ]]; then
|
||||
_kill STOP $pid $user
|
||||
elif [[ "$action" == "quit" ]]; then
|
||||
_kill QUIT $pid $user
|
||||
elif [[ "$action" == "hangup" ]]; then
|
||||
_kill HUP $pid $user
|
||||
fi
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
current_session=$(tmux display-message -p | sed -e 's/^\[//' -e 's/\].*//')
|
||||
if [[ -z "$TMUX_FZF_SESSION_FORMAT" ]]; then
|
||||
sessions=$(tmux list-sessions | grep -v "^$current_session: ")
|
||||
else
|
||||
sessions=$(tmux list-sessions -F "#S: $TMUX_FZF_SESSION_FORMAT" | grep -v "^$current_session: ")
|
||||
fi
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
if [[ -z "$1" ]]; then
|
||||
action=$(printf "switch\nnew\nrename\ndetach\nkill\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
if [[ "$action" != "detach" ]]; then
|
||||
if [[ "$action" == "new" ]]; then
|
||||
tmux split-window -v -p 30 -b -c '#{pane_current_path}' \
|
||||
'printf "Session Name: " && read session_name && tmux new-session -d -s ${session_name} && tmux switch-client -t ${session_name}'
|
||||
exit
|
||||
fi
|
||||
if [[ "$action" == "kill" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target session(s). Press TAB to mark multiple items.'"
|
||||
else
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target session.'"
|
||||
fi
|
||||
if [[ "$action" == "switch" ]]; then
|
||||
target_origin=$(printf "%s\n[cancel]" "$sessions" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
else
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$sessions" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_session:/")
|
||||
fi
|
||||
else
|
||||
tmux_attached_sessions=$(tmux list-sessions | grep 'attached' | grep -o '^[[:alpha:][:digit:]_-]*:' | sed 's/.$//g')
|
||||
sessions=$(echo "$sessions" | grep "^$tmux_attached_sessions")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target session(s). Press TAB to mark multiple items.'"
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$sessions" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_session:/")
|
||||
fi
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
target=$(echo "$target_origin" | sed -e 's/:.*$//')
|
||||
if [[ "$action" == "switch" ]]; then
|
||||
tmux switch-client -t "$target"
|
||||
elif [[ "$action" == "detach" ]]; then
|
||||
echo "$target" | xargs -I{} tmux detach -s "{}"
|
||||
elif [[ "$action" == "kill" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux kill-session -t "{}"
|
||||
elif [[ "$action" == "rename" ]]; then
|
||||
tmux command-prompt -I "rename-session -t $target "
|
||||
fi
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
current_window_origin=$(tmux display-message -p '#S:#I: #{window_name}')
|
||||
current_window=$(tmux display-message -p '#S:#I:')
|
||||
|
||||
if [[ -z "$TMUX_FZF_WINDOW_FILTER" ]]; then
|
||||
window_filter="-a"
|
||||
else
|
||||
window_filter="-f \"$TMUX_FZF_WINDOW_FILTER\""
|
||||
fi
|
||||
|
||||
if [[ -z "$TMUX_FZF_WINDOW_FORMAT" ]]; then
|
||||
windows=$(tmux list-windows $window_filter)
|
||||
else
|
||||
windows=$(tmux list-windows $window_filter -F "#S:#{window_index}: $TMUX_FZF_WINDOW_FORMAT")
|
||||
fi
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
action=$(printf "switch\nlink\nmove\nswap\nrename\nkill\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
if [[ "$action" == "link" ]]; then
|
||||
cur_ses=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
|
||||
last_win_num=$(tmux list-windows | sort -r | sed '2,$d' | sed 's/:.*//')
|
||||
windows=$(echo "$windows" | grep -v "^$cur_ses")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select source window.'"
|
||||
src_win_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$src_win_origin" == "[cancel]" || -z "$src_win_origin" ]] && exit
|
||||
src_win=$(echo "$src_win_origin" | sed 's/: .*//')
|
||||
tmux link-window -a -s "$src_win" -t "$cur_ses"
|
||||
elif [[ "$action" == "move" ]]; then
|
||||
cur_ses=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
|
||||
last_win_num=$(tmux list-windows | sort -r | sed '2,$d' | sed 's/:.*//')
|
||||
windows=$(echo "$windows" | grep -v "^$cur_ses")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select source window.'"
|
||||
src_win_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$src_win_origin" == "[cancel]" || -z "$src_win_origin" ]] && exit
|
||||
src_win=$(echo "$src_win_origin" | sed 's/: .*//')
|
||||
tmux move-window -a -s "$src_win" -t "$cur_ses"
|
||||
else
|
||||
if [[ "$action" == "kill" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target window(s). Press TAB to mark multiple items.'"
|
||||
else
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target window.'"
|
||||
fi
|
||||
if [[ "$action" != "switch" ]]; then
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_window_origin/")
|
||||
else
|
||||
windows=$(echo "$windows" | grep -v "^$current_window")
|
||||
target_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
fi
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
target=$(echo "$target_origin" | sed 's/: .*//')
|
||||
if [[ "$action" == "kill" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux unlink-window -k -t {}
|
||||
elif [[ "$action" == "rename" ]]; then
|
||||
tmux command-prompt -I "rename-window -t $target "
|
||||
elif [[ "$action" == "swap" ]]; then
|
||||
windows=$(echo "$windows" | grep -v "^$target")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select another target window.'"
|
||||
target_swap_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$target_swap_origin" == "[cancel]" || -z "$target_swap_origin" ]] && exit
|
||||
target_swap=$(echo "$target_swap_origin" | sed 's/: .*//')
|
||||
tmux swap-pane -s "$target" -t "$target_swap"
|
||||
elif [[ "$action" == "switch" ]]; then
|
||||
echo "$target" | sed 's/:.*//g' | xargs -I{} tmux switch-client -t {}
|
||||
echo "$target" | xargs -I{} tmux select-window -t {}
|
||||
fi
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue