Skip to content

Commit

Permalink
Merge branch 'awerebea-remove-duplicate-tabs-on-startup'
Browse files Browse the repository at this point in the history
Regenerate Ranger man page because of conflicts.
  • Loading branch information
toonn committed Apr 25, 2023
2 parents 478d5b6 + 504d5ef commit fe7c3b2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 24 deletions.
8 changes: 7 additions & 1 deletion doc/ranger.1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "RANGER 1"
.TH RANGER 1 "ranger-1.9.3" "2023-04-05" "ranger manual"
.TH RANGER 1 "ranger-1.9.3" "2023-04-25" "ranger manual"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down Expand Up @@ -1011,6 +1011,12 @@ on top of those for \fIdraw_borders\fR:
.IX Item "draw_progress_bar_in_status_bar [bool]"
Draw a progress bar in the status bar which displays the average state of all
currently running tasks which support progress bars?
.IP "filter_dead_tabs_on_startup [bool]" 4
.IX Item "filter_dead_tabs_on_startup [bool]"
Remove tabs with unavailable paths on startup. Setting this to false (the
default) will keep all saved tabs, even if their path is no longer reachable.
This can be useful to save tabs with paths on removable media or network
volumes.
.IP "flushinput [bool] <zI>" 4
.IX Item "flushinput [bool] <zI>"
Flush the input after each key hit? One advantage is that when scrolling down
Expand Down
7 changes: 7 additions & 0 deletions doc/ranger.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,13 @@ on top of those for I<draw_borders>:
Draw a progress bar in the status bar which displays the average state of all
currently running tasks which support progress bars?

=item filter_dead_tabs_on_startup [bool]

Remove tabs with unavailable paths on startup. Setting this to false (the
default) will keep all saved tabs, even if their path is no longer reachable.
This can be useful to save tabs with paths on removable media or network
volumes.

=item flushinput [bool] <zI>

Flush the input after each key hit? One advantage is that when scrolling down
Expand Down
3 changes: 3 additions & 0 deletions ranger/config/rc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ set one_indexed false
# Save tabs on exit
set save_tabs_on_exit false

# Remove tabs with unavailable paths on startup
set filter_dead_tabs_on_startup false

# Enable scroll wrapping - moving down while on the last item will wrap around to
# the top and vice versa.
set wrap_scroll false
Expand Down
1 change: 1 addition & 0 deletions ranger/container/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'draw_borders': str,
'draw_borders_multipane': str,
'draw_progress_bar_in_status_bar': bool,
'filter_dead_tabs_on_startup': bool,
'flushinput': bool,
'freeze_files': bool,
'global_inode_type_filter': str,
Expand Down
5 changes: 4 additions & 1 deletion ranger/core/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,10 @@ def tab_open(self, name, path=None):
if path:
tab.enter_dir(path, history=True)
else:
tab.enter_dir(tab.path, history=False)
if os.path.isdir(tab.path):
tab.enter_dir(tab.path, history=False)
else:
tab.thisdir = None

if tab_has_changed:
self.change_mode('normal')
Expand Down
10 changes: 10 additions & 0 deletions ranger/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def main(
profile = None
exit_msg = ''
exit_code = 0
startup_path_tab_index = 0
try: # pylint: disable=too-many-nested-blocks
# Initialize objects
fm = FM(paths=paths)
Expand Down Expand Up @@ -160,7 +161,15 @@ def main(
try:
with open(tabs_datapath, 'r', encoding="utf-8") as fobj:
tabs_saved = fobj.read().partition('\0\0')
startup_path = fm.start_paths.pop(0)
fm.start_paths += tabs_saved[0].split('\0')
# Remove dead entries if this behavior is defined in settings
if fm.settings.filter_dead_tabs_on_startup:
fm.start_paths = list(filter(os.path.isdir, fm.start_paths))
try:
startup_path_tab_index = fm.start_paths.index(startup_path)
except ValueError:
fm.start_paths.insert(0, startup_path)
if tabs_saved[-1]:
with open(tabs_datapath, 'w', encoding="utf-8") as fobj:
fobj.write(tabs_saved[-1])
Expand All @@ -172,6 +181,7 @@ def main(

# Run the file manager
fm.initialize()
fm.tab_move(startup_path_tab_index)
ranger.api.hook_init(fm)
fm.ui.initialize()

Expand Down
52 changes: 32 additions & 20 deletions ranger/gui/widgets/titlebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,40 @@ def _get_left_part(self, bar):
bar.add(self.fm.hostname, 'hostname', clr, fixed=True)
bar.add(' ', 'hostname', clr, fixed=True)

pathway = self.fm.thistab.pathway
if self.settings.tilde_in_titlebar \
and (self.fm.thisdir.path.startswith(self.fm.home_path + "/")
or self.fm.thisdir.path == self.fm.home_path):
pathway = pathway[self.fm.home_path.count('/') + 1:]
bar.add('~/', 'directory', fixed=True)

for path in pathway:
if path.is_link:
clr = 'link'
else:
clr = 'directory'

bidi_basename = self.bidi_transpose(path.basename)
bar.add(bidi_basename, clr, directory=path)
if self.fm.thisdir:
pathway = self.fm.thistab.pathway
if self.settings.tilde_in_titlebar \
and (self.fm.thisdir.path.startswith(
self.fm.home_path + "/") or self.fm.thisdir.path == self.fm.home_path):
pathway = pathway[self.fm.home_path.count('/') + 1:]
bar.add('~/', 'directory', fixed=True)

for path in pathway:
if path.is_link:
clr = 'link'
else:
clr = 'directory'

bidi_basename = self.bidi_transpose(path.basename)
bar.add(bidi_basename, clr, directory=path)
bar.add('/', clr, fixed=True, directory=path)

if self.fm.thisfile is not None and \
self.settings.show_selection_in_titlebar:
bidi_file_path = self.bidi_transpose(self.fm.thisfile.relative_path)
bar.add(bidi_file_path, 'file')
else:
path = self.fm.thistab.path
if self.settings.tilde_in_titlebar \
and (self.fm.thistab.path.startswith(
self.fm.home_path + "/") or self.fm.thistab.path == self.fm.home_path):
path = path[len(self.fm.home_path + "/"):]
bar.add('~/', 'directory', fixed=True)

clr = 'directory'
bar.add(path, clr, directory=path)
bar.add('/', clr, fixed=True, directory=path)

if self.fm.thisfile is not None and \
self.settings.show_selection_in_titlebar:
bidi_file_path = self.bidi_transpose(self.fm.thisfile.relative_path)
bar.add(bidi_file_path, 'file')

def _get_right_part(self, bar):
# TODO: fix that pressed keys are cut off when chaining CTRL keys
kbuf = str(self.fm.ui.keybuffer)
Expand Down
5 changes: 3 additions & 2 deletions ranger/gui/widgets/view_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def finalize(self):
pass
else:
col_x = self.main_column.x
col_y = self.main_column.y + self.main_column.target.pointer \
- self.main_column.scroll_begin
col_y = self.main_column.y - self.main_column.scroll_begin
if self.main_column.target:
col_y += self.main_column.target.pointer
try:
self.fm.ui.win.move(col_y, col_x)
except curses.error:
Expand Down

0 comments on commit fe7c3b2

Please sign in to comment.