Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vifm session strategy #500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions strategies/vifm_session.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

# "vifm session strategy"
#
# Restores a vifm session from the command line arguments.
# vifm can be run from command line in particular session,
# e.g. `vifm -c "session foo"`.
# NOTE: the strategy doesn't work if a session is created/changed
# in vifm, e.g. `:session bar` vifm command

ORIGINAL_COMMAND="$1"
DIRECTORY="$2"

main() {
local in_arg=0
local in_quote=0
local cmd=""
for word in $ORIGINAL_COMMAND; do
if [[ $word == -* ]]; then
if [[ $in_quote -eq 1 ]]; then
cmd+="\""
in_quote=0
fi
in_arg=1
cmd+=" $word"
continue;
fi

if [[ $in_arg -eq 0 ]]; then
cmd+=" $word"
continue
fi

if [[ $in_quote -eq 0 ]]; then
cmd+=" \"$word"
in_quote=1
else
cmd+=" $word"
fi

done

if [[ $in_quote -eq 1 ]]; then
cmd+="\""
fi

echo $cmd
}
main